定位不到元素
来源:3-2 最普通的自动化“裸奔状态”

慕粉1926212165
2022-04-29
import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
打开浏览器
driver = webdriver.Chrome(“E:\ChromeDownSoft\chromedriver_win32\chromedriver.exe”)
打开网页
driver.get(“http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html”)
登录
driver.find_element(“id”, “account”).send_keys(“admin”)
driver.find_element_by_css_selector(“input[name=‘password’]”).send_keys(“admin123456”)
driver.find_element_by_id(“submit”).click()
登录断言
text = WebDriverWait(driver,180,0.5).
until(lambda x: x.find_element_by_xpath("//div[@class=‘user-profile-name’]")).text
if text == “admin”:
print(“pass”)
else:
print(“fail”)
关闭浏览器
driver.quit()
报错:
Traceback (most recent call last):
File “E:\PyCharmProject\AutoTestBySelenium\login.py”, line 21, in
until(lambda x: x.find_element_by_xpath("//div[@class=‘user-profile-name’]")).text
File “D:\Users\wangyunju\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py”, line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
1回答
-
托尼老师
2022-05-17
同学,//div[@class=‘user-profile-name’]对应页面上哪个元素?
00
相似问题