我以为我明白这个概念,但我想我不明白
我想从HTML页面的选项卡列表中单击一个按钮
<div id="subTabs2">
<div id="subTabs">
<ul>
<li>
<a class="currentTab" id="sub_tab_timeclock_today" href="?p=timeclock:today">Today</a>
</li>
<li>
<a id="sub_tab_timeclock_my_timesheet" href="?p=timeclock:my_timesheet">My timesheet</a>
</li>
#list continues ....
我想点击标签“sub_tab_timeclock_my_timesheet”,所以在我的代码中我点击了
# some code
driver = webdriver.Chrome(driverPath)
driver.get(url)
username = driver.find_element_by_id("user_handle")
password = driver.find_element_by_id("user_password")
username.send_keys("myUser")
password.send_keys("myPass")
driver.find_element_by_class_name("button1").click()
driver.find_element_by_id("sub_tab_timeclock_my_timesheet").click()
我确实通过了登录页面,但我不明白为什么我的代码不能用于单击ID为“sub_tab\u timeclock\u my_timesheet”的选项卡“my timesheet”
错误消息是:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="sub_tab_timeclock_my_timesheet"]"}
(Session info: chrome=85.0.4183.83)
我做错了什么
谢谢
看起来你可能遇到了时间问题。尝试在
driver.find_element_by_class_name("button1").click()
和driver.find_element_by_id("sub_tab_timeclock_my_timesheet").click()
之间实现等待为此,您需要执行以下操作:
由于我是.NET开发人员,因此对Python代码不太确定,但请查看本文中的语法细节: https://selenium-python.readthedocs.io/waits.html
相关问题 更多 >
编程相关推荐