我有这个问题
我尝试过
driver.implicitly_wait(20)
但无法正常工作,并且存在相同的问题
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#user_username"}
(Session info: chrome=75.0.3770.100)
网站加载后显示的内容
我无法访问表格 这是表格链接 https://accounts.esri.com/en/login
这是简单的代码
from selenium import webdriver
URL = 'https://accounts.esri.com/en/login'
userName = 'test'
passWord = 'test'
driver = webdriver.Chrome()
driver.get(URL)
time.sleep(10)
passWordInput = driver.find_element_by_css_selector('#user_username')
passWordInput.send_keys(userName)
passWordInput = driver.find_element_by_css_selector('#user_password')
passWordInput.send_keys(passWord)
buttonSignIn = driver.find_element_by_css_selector('#signIn')
buttonSignIn.click()
time.sleep(5)
答案 0 :(得分:-1)
此表单位于<iframe>
内,对于浏览器,它是另一页,因此找不到它。您必须使用switch_to.frame
更改框架,然后才能在此框架中搜索。
from selenium import webdriver
import time
URL = 'https://accounts.esri.com/en/login'
userName = 'test'
passWord = 'test'
driver = webdriver.Chrome()
#driver = webdriver.Firefox()
driver.get(URL)
time.sleep(10)
f = driver.find_element_by_tag_name('iframe')
driver.switch_to.frame(f)
passWordInput = driver.find_element_by_css_selector('#user_username')
passWordInput.send_keys(userName)
passWordInput = driver.find_element_by_css_selector('#user_password')
passWordInput.send_keys(passWord)
buttonSignIn = driver.find_element_by_css_selector('#signIn')
buttonSignIn.click()
time.sleep(5)