Python and Selenium To “execute_script” to solve “ElementNotVisibleException”

前端 未结 2 1936
天涯浪人
天涯浪人 2021-02-06 11:08

I am using Selenium to save a webpage. The content of webpage will change once certain checkbox(s) are clicked. What I want is to click a checkbox then save the page content. (T

2条回答
  •  孤城傲影
    2021-02-06 11:30

    Alternative option would be to make the click() inside execute_script():

    # wait for element to become present
    wait = WebDriverWait(driver, 10)
    checkbox = wait.until(EC.presence_of_element_located((By.NAME, "keywords_here")))
    
    driver.execute_script("arguments[0].click();", checkbox)
    

    where EC is imported as:

    from selenium.webdriver.support import expected_conditions as EC
    

    Alternatively and as an another shot in the dark, you can use the element_to_be_clickable Expected Condition and perform the click in a usual way:

    wait = WebDriverWait(driver, 10)
    checkbox = wait.until(EC.element_to_be_clickable((By.NAME, "keywords_here")))
    
    checkbox.click()
    

提交回复
热议问题