I do a lot of web scraping to automate some of my job functions. I'm trying to populate this text-box on this website .
I've done this on about 10 other websites with no problems, but for some reason, this one is giving me trouble. I've searched all the entries on here from others doing this, but I don't see what I am missing.
Here is my code I am using. I'm using Visual Studio 2008, version 9.0.3. I've also tried invokemember click after setting the attribute etc. It finds the element, so I know I am getting that far, the text-box is just not populating. Any help would be really appreciated.
Thanks.
theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
If curElement.OuterHtml.Contains("ctl00$CPHContent$txtUserID") Then
WebBrowser1.Document.GetElementById("ctl00_CPHContent_txtUserID").SetAttribute("value", "TEST")
Exit For
End If
Next
This is the code I used, and it appears to work fine most of the time.
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim userNameElement As HtmlElement = Nothing
userNameElement = WebBrowser1.Document.GetElementById("ctl00_CPHContent_txtUserID")
If Not Nothing Is userNameElement Then
userNameElement.SetAttribute("value", "TESTing")
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("https://providerportal.careimprovementplus.com/Login.aspx")
End Sub
The first couple times it wouldn't set the attribute. But after the page was cached it worked perfect every time. There's probably a weird timing issue. I bet if you put a Thread.Sleep(250)
as the first statement in the DocumentCompleted
event it would solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.