Is there a way to detect if javascript is executing a script using either JQuery, javascript, WebDriver, or C# (like a browser API or something)?
For example, say I’m on a webpage and I just selected a U.S. State (let’s say California) from a picklist, and some javascript is now loading a second picklist with all the cities found in California. How can I detect if javascript is executing, and when it has finished?
I’m running into problems with WebDriver since it doesn’t know how to wait for a script to stop executing aside from pausing for a few seconds.
Your question could be taken several ways.
Are you trying to see if javascript is enabled on the browser from your server-side code? I have done this by sending a small page with a form field and some javascript to populate that field and post-back. if the post-back doesn’t happen, the page says something about ‘javascript must be enabled.’ If it DOES postback, I know Javascript is enabled.
If you’re are client-side and you need to wait for something to complete, like loading your US State pull-down you need to wire up on-completion type events. Browsers are asynchronous by nature (that’s a good thing) so you need to ‘register’ callbacks for key things to know when they’ve completed.
Without specific markup or situations it’s tough to offer more.