I have a very simple requirement to load a web page, wait until it's finished loading, and then wait for an element to become present/visible (this only happens after the page has signaled that it finished loading) before doing anything else with the page.
I tried using the WebBrowser control, but struggled with finding a way to wait for the element.
I looked at using CefSharp but I was told the only way is to inject js, which I'm not all that keen on doing.
I also looked at Selenium WebDriver too and the WebDriverWait
appears to do exactly what I want, but the fact that it's not actually a control, cannot be hidden and requires browsers to be installed is a no-no for me.
Is there a way of doing this which does not involve using Thread.Sleep
in either WebBrowser, CefSharp or any other project I haven't mentioned yet?
EDIT: Some extra information...
I am using this for web automation. In this particular instance to login to a website (I'm not storing passwords, don't worry).
The particular website in question supports different authentication methods at a user level, so after entering the username it runs a js script which determines whether to then ask for the password or for something like phone auth, smartcard auth, etc. The js script does not fire the DocumentCompleted
event, which is what I'm struggling with at the moment.
The idea is that if it asks for smartcard or phone auth to keep the form/control with .Visible = false
the whole time and just show it if the user is set for username/password auth.
So depending on what happens after I automate entering the username, it will either ask for a password, smartcard or phone auth and I need to wait for the DOM to change so that one of those 3 elements becomes visible so I know what to do.
I dislike Selenium because it involves the user having to install browsers, it's hard/impossible to make it hidden, it's not an actual control I can drop on my form, etc etc.