繁体   English   中英

在 python 中使用 Selenium 而不使用 Id 或使用 XPath 单击按钮

[英]Click Button in python Using Selenium Without Id Or Using XPath

所以我试图使用 xpath、绝对 xpath 和类名点击这个编辑按钮,但我没有运气。

 <a class="button" type="button" href="/tas/secure/hardware?action=edit&amp;unid=aff0d17eccb446e0a3c14f8ab21e307c&amp;id=52797238dc6848c1baa64958b3663774&amp;linkstructuretable=object&amp;realstructuretable=hardware&amp;componentstate=1&amp;archived=false&amp;newcomponent=false&amp;editable=false&amp;activatedtabParameter=&amp;parentContextId=c18L&amp;mangle=false">Edit</a>

你有没有试过。

//a[starts-with(@href,'/tas/secure/hardware')]

编辑 1:需要进口

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

代码:

ele = WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,"//a[starts-with(@href,'/tas/secure/hardware')]")))
``

尝试使用 css 选择器:

driver.find_element_by_css_selector('a[href^="/tas/secure/hardware"]').click()

或链接文字:

driver.find_element_by_link_text('Edit').click()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM