-
Oct 22nd, 2022, 05:45 AM
#1
Thread Starter
Addicted Member
Webbrowser Invoke problems
Hello All
I am trying to save a html table from a website to a .csv file.
However, I have issues invoking an element. I have managed to login into the site, but cannot work out how to invoke a element (it is just text - no button).
My VB code is (I have asterixed the username and password - but I can assure you its working) :
Code:
Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
WebBrowser1.Navigate("https://csonline.eskom.co.za")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
WebBrowser1.Document.GetElementById("accountNumber").SetAttribute("value", "********")
WebBrowser1.Document.GetElementById("accountPassword").SetAttribute("value", "*******")
WebBrowser1.Document.Forms(0).InvokeMember("submit")
WebBrowser1.Document.Forms(0).InvokeMember("f10_linkThreeButton")
End Sub
End Class
I cannot invoke the text (ID is f10_linkThreeButton) with WebBrowser1.Document.Forms(0).InvokeMember("f10_linkThreeButton").
The inspect element from the website is :
Code:
<a href="javascript:void(0);" style="" id="f10_linkThreeButton" class="GTHREFButton linkThreeButton quickLinks GTTextButtonH GTVI GTTextFieldAC " onfocus="gainFocus('f10_linkThreeButton');" onblur="looseFocus();" onclick="clientAPI.postEvent('f10_linkThreeButton',4);return false;" tabindex="-1" title="View your consumption history.">View Consumption History</a>
Any help would be much appreciated.
Regards
-
Oct 22nd, 2022, 09:14 AM
#2
Re: Webbrowser Invoke problems
Surely you have to wait for the login to be processed before invoking that second link.
-
Oct 23rd, 2022, 02:10 AM
#3
Thread Starter
Addicted Member
Re: Webbrowser Invoke problems
Thank you for replying jmcilhinney.
I can login with Button3_Click. In the webbrowser window the login is successful, but when I try to invoke the second link, nothing happens ( no error messages).
If I click on the link in the webbrowser window in my application I get an error : On error has occurred in the script on this page 'CLientAPI' is indefined.
-
Oct 23rd, 2022, 03:10 AM
#4
Re: Webbrowser Invoke problems
Originally Posted by GideonE
Thank you for replying jmcilhinney.
I can login with Button3_Click. In the webbrowser window the login is successful, but when I try to invoke the second link, nothing happens ( no error messages).
If I click on the link in the webbrowser window in my application I get an error : On error has occurred in the script on this page 'CLientAPI' is indefined.
Trying to automate websites is often a bad idea and should only be a last resort. Quite often websites are designed to deliberately prevent this kind of automation (captchas etc.), even when they aren't deliberately stopping automation working, they can be really problematic to automate; often they will break at some point later as the website designer changes things anyway. Additionally this may even be against the T&Cs of the site in question as well.
Often it is better to see if an API is provided instead of trying to automate things.
-
Oct 23rd, 2022, 03:38 AM
#5
Re: Webbrowser Invoke problems
If you were doing this as a normal user in a web browser, would you have to wait after clicking submit before the second click?
-
Oct 24th, 2022, 10:30 AM
#6
Thread Starter
Addicted Member
Re: Webbrowser Invoke problems
-
Oct 24th, 2022, 10:34 AM
#7
Re: Webbrowser Invoke problems
So, given that there's basically zero delay between those two actions in your code, can you see the problem? There is obviously no such link in the current page because the page containing that link hasn't loaded yet, because you haven't waited for it to load.
-
Oct 25th, 2022, 10:15 AM
#8
Thread Starter
Addicted Member
Re: Webbrowser Invoke problems
Adding System.Threading.Thread.Sleep(5000) before the second link made no difference.
-
Oct 25th, 2022, 10:30 AM
#9
Re: Webbrowser Invoke problems
That's not the solution. The solution is wait until the next page has loaded. That's why the WebBrowser has a DocumentLoaded (or the like) event.
-
Oct 25th, 2022, 01:52 PM
#10
Re: Webbrowser Invoke problems
The event is DocumentCompleted. You need to test for ReadyState before attempting to click the button. The values are...
Complete 4
The control has finished loading the new document and all its contents.
Interactive 3
The control has loaded enough of the document to allow limited user interaction, such as clicking hyperlinks that have been displayed.
Loaded 2
The control has loaded and initialized the new document, but has not yet received all the document data.
Loading 1
The control is loading a new document.
Uninitialized 0
No document is currently loaded.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|