![]() |
|
[.NET] Webbrowser: Wait Until Element is Present - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Webbrowser: Wait Until Element is Present (/showthread.php?tid=5819988) |
Webbrowser: Wait Until Element is Present - ThatAlbinoFrog - Apr 3, 2018 Hey! Simple question, is there any way I can get a webbrowser to wait until an element is present? I'm not an amazing coder, so here's my best example of what I'm trying to do - Code Do While PageLoaded = FalseThe problem with this is that the element doesn't have an ID, so when I'm trying to do something like click it, I have to do something like this - Code For Each altelm As HtmlElement In WebBrowser1.Document.GetElementsByTagName("SPAN")I've tried using documentcompleted, but the element loads in after the page, meaning I have to scroll down to load it in. Currently a timer works but if other people use this program with proxies or slower internet, the timer would have to be different. I apologise if this is worded poorly, I'm new to this :) Thanks! RE: Webbrowser: Wait Until Element is Present - Ninja - Apr 3, 2018 If I recall correctly the DocumentCompleted event could fire multiple times. Try checking if the ReadyState property equals WebBrowserReadyState.Complete, and if so then proceed. Though the WebBrowser component is one of the most unreliable things to make bots/automation tools with. If the task is not too complicated you can try and use the HttpClient, which is much more reliable. RE: Webbrowser: Wait Until Element is Present - SIM-2362662 - Apr 3, 2018 Send the whole code (with the timer included) RE: Webbrowser: Wait Until Element is Present - Apparatus - Apr 4, 2018 Have the timer start once the element is detected in the document completed event. Then have an if statement that detects if the timer is running to keep it from firing multiple times like Ninja said. You should try out geckofx if you're wanting to do this via web browser. The default control isn't so great lol. RE: Webbrowser: Wait Until Element is Present - Mike Tyler - Jul 28, 2018 PHP Code RE: Webbrowser: Wait Until Element is Present - iphone5s - Jul 31, 2018 Recently I also faced the same problem but couldn't find solution anywhere and DocumentCompleted event also doesn't always work like you wanted, so I created my own solution this solution works best in multi-threading and also eliminates the problem of waiting for the element for a specific time. Here's the code I use to wait for webbrowser control to finish initial page loading: https://pastebin.com/0aEqKtHi RE: Webbrowser: Wait Until Element is Present - ThatAlbinoFrog - Jul 31, 2018 (Jul 31, 2018 04:50 AM)iphone5s Wrote: Recently I also faced the same problem but couldn't find solution anywhere and DocumentCompleted event also doesn't always work like you wanted, so I created my own solution this solution works best in multi-threading and also eliminates the problem of waiting for the element for a specific time. Ah nice man, I just went for a Loopcount like this - Code Dim waitcount As Integer = 0 |