[Python] 纯文本查看 复制代码
from selenium import webdriver
b = webdriver.Chrome()
b.get('http://www.baidu.com')
b.find_element_by_xpath('//*[@id="u1"]/a[7]').click()
b.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__footerULoginBtn"]').click()
# 输入用户名和密码
b.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__userName"]').send_keys('输入百度账户名')
b.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__password"]').send_keys('输入百度账户密码')
# 点击登录
b.find_element_by_id('TANGRAM__PSP_10__submit').click()
[Python] 纯文本查看 复制代码
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="TANGRAM__PSP_10__footerULoginBtn"]"}
(Session info: chrome=75.0.3770.80)
(Driver info: chromedriver=75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40}),platform=Mac OS X 10.13.6 x86_64)
[Python] 纯文本查看 复制代码
from selenium import webdriver
import time
b = webdriver.Chrome()
b.get('http://www.baidu.com')
b.find_element_by_xpath('//*[@id="u1"]/a[7]').click()
# 延时两秒,不然无法点击用户名登录
time.sleep(2)
b.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__footerULoginBtn"]').click()
# 输入用户名和密码
b.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__userName"]').send_keys('账号')
b.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__password"]').send_keys('密码')
# 点击登录
b.find_element_by_id('TANGRAM__PSP_10__submit').click()