简体   繁体   中英

Python Selenium time out explicitly

My script does not come out to execute the next line after clicking below link.

monkey_click_by_id(driver, "fwupdatelink")

Is there any way to come out after clicking it explicitly without fail?

The issue could be that the webdriver moves on too quickly before your scripts gets a chance to get the information it needs. my suggestions is to make it wait until the element is loaded by visibility which would be the same as an actual user seeing the link show up in their browser. just to be safe.

try adding this code before your script. it waits for the element with ID "fwupdatelink" to be visible or otherwise just 10 second which ever is shorter.

from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.ID,"fwupdatelink"))) 

You could also use a try/except statement, just in case your driver gives you a timeout error.

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