selenium.common.exceptions.ElementNotVisibleException: Message: element not visible while trying to access an element with Python + Selenium

后端 未结 3 994
执笔经年
执笔经年 2020-11-27 08:38

I am trying to enter username and password in the following website: https://www.thegreatcoursesplus.com/sign-in

driver = webdriver.Chrome()
driver.get(\'htt         


        
3条回答
  •  粉色の甜心
    2020-11-27 09:26

    There are two problems:

    • The first one is timing, it takes some time for the form to appear. You you can use explicit wait to solve it.
    • The second one is that the field id in tag, not

      tag, and there are many fields that matches this xpath. I suggest you locate the form holding the fields and use it to locate each field

    For the timing issue you can use explicit wait

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = webdriver.Chrome()
    driver.get('https://www.TheGreatCoursesPlus.com/sign-in')
    form = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[@class="modal-body"]//form')))
    
    form.find_element_by_name('email').send_keys(email)
    form.find_element_by_name('password').send_keys(password)
    form.find_element_by_name('sign-in-button').click()
    

提交回复
热议问题