Selenium - wait until element is present, visible and interactable

前端 未结 4 2005
旧时难觅i
旧时难觅i 2020-11-22 01:41

I have a selenium script (python) that clicks a reply button to make the class anonemail appear. The time it takes for the class anonemail to appear varies. Because of that

4条回答
  •  不知归路
    2020-11-22 02:23

    After click reply button, use .visibility_of_element_located like bellow:

    browser.find_element_by_css_selector(".reply-button").click()
    
    #wait initialize, in seconds
    wait = WebDriverWait(browser, 10)
    
    email = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.anonemail'))).get_attribute("value")
    print(email)
    

    Following import:

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

    Waits docs

提交回复
热议问题