How to locate the username and password field within Instagram login page using Chromedriver and Selenium Python

后端 未结 4 1673
梦毁少年i
梦毁少年i 2021-01-26 21:50

Here\'s inspected source code

input aria-label=\"Phone number, username, or email\" aria-required=\"true\" autocapitalize=\"off\" autocorrect=\"off\" maxlength=\         


        
4条回答
  •  被撕碎了的回忆
    2021-01-26 22:19

    Observe that while open instagram homepage, it shows spinner on login form for few moment and then display the fields. So your need to manage synchronization in your script.

    Use explicit wait in your code until desired field get ready for interaction.

    username = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='username']")))
    username.send_keys('username')
    password = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='password']")))
    password.send_keys('pw')
    

    Need to import below packages

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

提交回复
热议问题