Making VB Browser Make Facebook Status - facebook

I am trying to make a vb script to log into my facebook and update my status. The problem is, the submit button does not have an ID I can find using the page info with Chrome. The script I have so far is:
Try
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("pathtotext") ' I sensoored my path
fileReader2 = My.Computer.FileSystem.ReadAllText("pathtotext") 'I sensored my path
WebBrowser1.Document.GetElementById("email").SetAttribute("value", fileReader2)
WebBrowser1.Document.GetElementById("pass").SetAttribute("value", fileReader)
WebBrowser1.Document.GetElementById("loginbutton").InvokeMember("click")
Catch ex As Exception
WebBrowser1.Document.GetElementById("u_0_10").SetAttribute("value", "Can I make a status?")
WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
End Try
All of this works, except the submit button. I used "submit" because that was the type and no ID is showing up. Thanks in advance for all help.
P.S - For future reference, how did you find the id for this button? "If you give a starving man a fish he shall be filled; teach him to fish, however and he shall never go hungry again" - Anonymous

you can use this
Dim htmlElements As HtmlElementCollection = WebBrowser1.Document.All
For Each ClickOnElementButton As HtmlElement In htmlElements
If ClickOnElementButton.InnerText = "Post" Then
ClickOnElementButton.InvokeMember("click")
End If
Next
instead of the old code

Related

Give forms a name with Macro in excel

At the moment I have a project with about 20 forms and sometimes I want to make small adjustments to them. So I created a piece of code to delete the forms and then recreate them the way I want.
The problem is that one line of code keeps giving me Path/File access error (Error 75).
This is a small piece of the code:
Sub makeForm(formName As String)
Dim form As Object
'These lines delete the old form
Set form = ThisWorkbook.VBProject.VBComponents(formName)
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=form
'This line creates the new form
Set form = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
'These lines give the new form a few properties
With form
.Properties("Name") = formName 'This is the line of code that gives the error
.Properties("Caption") = formName
.Properties("Width") = 320
.Properties("Height") = 242
End With
End Sub
Can someone please tell me how I can make sure this error no longer appears? By the way, this error also appears when I manually want to change the name of a form after this macro failed, but doesn't when I do it before the macro failed.
PS: I'm new to this site so sorry if I made any rookie mistakes.
Saving the workbook after you've removed the userform seems to clear the error.
'These lines delete the old form
Set form = ThisWorkbook.VBProject.VBComponents(formName)
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=form
Set form = Nothing
ThisWorkbook.Save
I guess Excel refreshes some internal values when it saves.

How to display modified body after Outlook ItemLoad

I have code to parse emails and add "tel:" links to phone numbers, but the modified email body doesn't get shown in the Outlook Reading Pane until the user manually reloads it (view another email, come back to this one).
I've tried a few hacks like Inspector.Display, and ActiveExplorer.ClearSelection ActiveExplorer.AddToSelection, but I can't get consistent results (Display will open new Inspectors for some users, very undesirable).
I was also going to investigate hooking the event sooner. Somehow accessing the email body before Outlook renders it, to avoid the need to refresh. I'm very new to VSTO, so I don't know what event would have access to the MailItem but happen after a user selects it and before it is rendered. I have thought about only processing new mail, but that doesn't help when I roll out this addin, only going forward.
Here is my current ItemLoad sub:
Private Sub Application_ItemLoad(Item As Object)
Dim myObj As Outlook.MailItem
Dim ob As Object
ob = GetCurrentItem()
If TypeOf ob Is Outlook.MailItem Then
myObj = ob
Dim oldbody As String = myObj.Body
If myObj.HTMLBody.Length > 0 Then
myObj.HTMLBody = RegularExpressions.Regex.Replace(myObj.HTMLBody, "(?<!tel:)(?<![2-9\.])(?<!\>\ )[+]?(1-)?(1)?[\(]?(?<p1>\d{3})[\)]?[\.\- ]?(?<p2>\d{3})[\.\- ]?(?<p3>\d{4})(?=[^\d])", " ${p1}-${p2}-${p3}")
Else
myObj.Body = RegularExpressions.Regex.Replace(myObj.Body, "(?<!tel:)(?<![2-9\.])[+]?(1-)?(1)?[\(]?(?<p1>\d{3})[\)]?[\.\- ]?(?<p2>\d{3})[\.\- ]?(?<p3>\d{4})(?=[^\d])", "tel:${p1}.${p2}.${p3}")
End If
myObj.Save()
refreshCurrentMessage()
End If
End Sub
GetCurrentItem() just returns either objApp.ActiveExplorer.Selection.Item(1) or objApp.ActiveInspector.CurrentItem based on TypeName(objApp.ActiveWindow)
Outlook doesn't reflect changes made through the OOM immediately. You need to switch to another folder/email to get the item refreshed because there is no way to update the item on the fly.
You can use the CurrentFolder property of the Explorer class which allows to set a Folder object that represents the current folder displayed in the explorer. Thus, the view will be switched to another folder. Then you can set the CurrentFolder folder to initial folder.
Also I'd suggest releasing all underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object.

How to validate custom ("%CUSTOM%) RulesStringValue in Fiddler?

I have following piece of code in my fiddlerscript:
RulesString("Redirect Foo", true)
RulesStringValue(0, "to the latest version", "latest")
RulesStringValue(1, "to a particular version... (e.g. 1.2.3)", "%CUSTOM%")
public static var foo_redirect: String = null;
It renders as a submenu and clicking Redirect Foo to a particular version... opens a prompt box where you can type something.
Now, I want to validate that the user typed something following a regexp, and not a totally random string, and display a FiddlerObject.alert if he put something non-conformant.
How can I do the validation just after the user inputs the value, but before there's any redirection happening? (I don't want to defer it to OnBeforeRequest since it may display dozens of alerts there, one per each session - Foo is a folder with many JS files).
Fiddler does not offer a mechanism to validate the values of the %CUSTOM% token at the point of entry. If you want to do that, don't use RulesString, instead use FiddlerScript or an extension to add a menu of your own devising.

Redirect to last page when overlay comment-form is used

I've got a view (phase4) with some custom content type content in it, where the users may comment on.
When the users want to comment, the comment form should appear in a modal form. I solved this by using the admin overlay.
Adding following function to my custom module:
function phase2_admin_paths_alter(&$paths) {
$paths['comment/reply/*'] = TRUE;
}
and using following link:
Comment
to open the comment form in a modal way. So far so good... but....
How do I redirect the user back to the page, the user was coming from.
I know that I have to overwrite the #action of the form in the template_form_FORMID_alter, like
$form['#action'] = $lasturl;
but how do I get the last url, so that it is reusable (so hardcoding the url isn't an option)?
My first idea was that I transfer the last url by adding it to the url as a $_GET-parameter, but it looks like this:
www.example.com/phase4#overlay=comment/reply/161%3Furl%3Dphase4
I also tried it with drupal_get_destination(), but either with no success, because of the tranformation of the "?" and the "=" in the url.
Are there other ways to find out where the user was coming from?
Note: phase4 isn't the alias of node 161. Phase 4 is a view, where node 161 is an element of.
Cheers
Tom
You have to use the drupal_get_destination() function with l() function to create such links.
$destination = drupal_get_destination(); // Store current path
Comment

Intrincate sites using htmlunit

I'm trying to dump the whole contents of a certain site using HTMLUnit, but when I try to do this in a certain (rather intrincate) site, I get an empty file (not an empty file per se, but it has an empty head tag, an empty body tag and that's it).
The site is https://www.abcdin.cl/abcdin/abcdin.nsf#https://www.abcdin.cl/abcdin/abcdin.nsf/linea?openpage&cat=Audio&cattxt=TV%20y%20Audio&catpos=03&linea=LCD&lineatxt=LCD%20&
And here's my code:
BufferedWriter writer = new BufferedWriter(new FileWriter(fullOutputPath));
HtmlPage page;
final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
webClient.setCssEnabled(false);
webClient.setPopupBlockerEnabled(true);
webClient.setRedirectEnabled(true);
webClient.setThrowExceptionOnScriptError(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setUseInsecureSSL(true);
webClient.setJavaScriptEnabled(true);
page = webClient.getPage(url);
dumpString += page.asXml();
writer.write(dumpString);
writer.close();
webClient.closeAllWindows();
Some people say that I need to introduce a pause in my code, since the page takes a while to load in Google Chrome, but I set long pauses and it doesn't work.
Thanks in advanced.
Just some ideas...
Retrieving that URL with wget returns a non-trivial HTML file. Likewise running your code with webClient.setJavaScriptEnabled(false). So it's definitely something to do with the Javascript in the page.
With Javascript enabled, I see from the logs that a bunch of Javascript jobs are being queued up, and I get see corresponding errors like this:
EcmaError: lineNumber=[49] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[https://www.abcdin.cl/js/jquery/jquery-1.4.2.min.js] message=[TypeError: Cannot read property "nodeType" from undefined (https://www.abcdin.cl/js/jquery/jquery-1.4.2.min.js#49)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "nodeType" from undefined (https://www.abcdin.cl/js/jquery/jquery-1.4.2.min.js#49)
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)
Maybe those jobs are meant to populate your HTML? So when they fail, the resulting HTML is empty?
The error looks strange, as HtmlUnit usually has no issues with JQuery. I suspect the issue is with the code calling that particular line of the JQuery library.