Python selenium 二级定位不了
源码# coding=utf-8
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("http://www.baidu.com/")
driver.find_element_by_name("tj_login").click()
div = driver.find_element_by_class_name("tong-content").find_element_by_name("userName")
div.send_keys("username")
driver.find_element_by_name("password").send_keys("password")
time.sleep(2)
driver.find_element_by_id("TANGRAM__PSP_10__submit").click()
driver.quit()
错误信息
D:\python\python.exe E:/其他/UV/bdlg.py
Traceback (most recent call last):
File "E:/����/UV/bdlg.py", line 7, in <module>
div = driver.find_element_by_class_name("tong-content").find_element_by_name("userName")
File "D:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "D:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 712, in find_element
{'using': by, 'value': value})['value']
File "D:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "D:\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"tong-content"}
Process finished with exit code 1
各位大大,帮帮忙:loveliness: 已解决
# coding=utf-8
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time
driver = webdriver.Firefox()
driver.get("http://www.baidu.com/")
driver.find_element_by_link_text("登录").click()
WebDriverWait(driver, 10).until(lambda the_driver: the_driver.find_element_by_id("TANGRAM__PSP_8__userNameWrapper").is_displayed())
div = driver.find_element_by_id("TANGRAM__PSP_8__userNameWrapper").find_element_by_name("userName")
div.send_keys("username")
driver.find_element_by_name("password").send_keys("password")
time.sleep(2)
driver.find_element_by_css_selector("input").click()
time.sleep(2)
driver.quit()
页:
[1]