How do you set Script Timeouts on Selenium Webdriver in Python?

遇到一個 driver.execute_async_script(“…”) 的時候, 如果使用者點擊網頁上的其他超連結, 會造成 main thread 被卡住的問題.

解法:
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.set_script_timeout

set_script_timeout(time_to_wait: float) → None

Set the amount of time that the script should wait during an execute_async_script call before throwing an error.

Args:time_to_wait: The amount of time to wait (in seconds)
Usage:driver.set_script_timeout(30)

Example:

driver.set_script_timeout(3)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *