简体   繁体   中英

I can't seem to locate the input box element using Python/Selenium

I am trying to use Python to automate something.

I can't seem to locate the email input element with driver.find_element_by_ . I tried so many different ways. I just want to be able to log into the website with Chromedriver.

<div class="css-1ilyui9">
    <input type="email" required="" class="css-cgadzw" value="">
</div>

The email input box doesn't have any attributes. No name or id. Class is not unique. Password box has the same class.

This is what I have so far. I just want Python to log in for me and go to a certain page periodically but I am unable to send_key because I can't find the element. It keeps saying "element not found".

from selenium import webdriver

chrome_path = r"C:\Users\peter\Desktop\chromedriver.exe"
driver = webdriver.Chrome(executable_path=r"C:\Users\peter\Desktop\chromedriver.exe")
driver.get("https://")
driver.find_element_by_xpath("//input[@type='email']")

Error Code:

selenium.common.exceptions.NoSuchElementException: 
Message: no such element: 
Unable to locate element: {"method":"xpath","selector":"//input[@type='email']"}
  (Session info: chrome=78.0.3904.108)

Try to use two identifiers in your selector:

driver.find_element_by_xpath("//input[@class='css-cgadzw'][@type='email']")

Also, you may need to put some wait in order to be able to see the element on page as refereed here

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