gpt4 book ai didi

python - 无法在 python 中使用 webdriver 单击元素

转载 作者:行者123 更新时间:2023-11-28 22:42:21 25 4
gpt4 key购买 nike

我需要有关在 python 中使用 selenium webdriver 单击元素的帮助。

这是供引用的html代码:我正在尝试单击名为“SYSTEM”的元素

<body>
<div id="toparea">
<div id="logo" style="top: 10px; z-index: 3">
<div id="welcome">
<div id="topmenu1">
<ul>
<li id="home" class="selected" style="right: 636px">
<li id="incidents" style="right: 530px">
<li id="case" style="right: 424px">
<li id="capture" style="right: 318px">
<li id="policies" style="right: 212px">
<li id="classify" style="right: 106px">
<li id="system" style="right: 0px">
<a onclick="location.href='/imanager/ReShowMenuBar.do?selectedtab=system'" title="SYSTEM" target="mainFrame" href="/devicemgr/ReSystemAdministration.do">SYSTEM</a>
</li>
</ul>

我尝试使用:

driver.find_element_by_xpath("//*[@id='system']/a")

尝试使用 link_text、id 查找元素,但都是徒劳的。

我也不确定我的xpath是否正确,我正在努力学习。

最佳答案

通过链接文本找到它:

driver.find_element_by_link_text("SYSTEM")

您可能需要 wait for the element to be clickable还有:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
system = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "SYSTEM")))
system.click()

关于python - 无法在 python 中使用 webdriver 单击元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31842954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com