简体   繁体   中英

How to detect if browser is running any javascript (without changing js on page)

I'm working on implementation of custom php client for selenium and I have a problem with implementing waitForPageToLoad() function:

the problem is that just checking document.readyState is not enough - there could be some JS script running on the page (for example, some animation after button click) that should force my waitForPageToLoad() function to continue waiting, but document.readyState returns complete status in such case.

Another problem is that I can't use callbacks as I don't know what js will be run on a page. Nonetheless I can insert some js on page but I must be sure that it will NOT influence on page's normal behavior.

Can anyone suggest a possible solution? Currently I'm working with latest FF browser.

Thanks.

It is not possible to check if JavaScript is currently running.

You can wait for elements to be present.

For Python, it would work like this:

from selenium.webdriver.support import expected_conditions as EC  # noqa

driver = webdriver.Chrome(...)

el = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//a"))  # change to your needs
)

See also: http://selenium-python.readthedocs.io/waits.html

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM