[英]Python Selenium grabbing an element by XPath
我目前正在尝试单击页面上的 X 按钮,这样它会带我离开当前页面,然后 go 返回主菜单。 我尝试通过 Xpath 复制它,但我一直收到错误 no such element
//*[@id="uniqName_85_2"]/header/div[2]/div/i[6]
这是 HTML
<i role="button" aria-label="Close" tabindex="0" class="tableCell
hi hi-close" data-dojo-attach-event="onclick:trowserExit">
任何帮助,将不胜感激。 我不确定为什么 xpath 不工作
使用WebDriverWait()
并等待element_to_be_clickable()
并遵循xpath
。
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//i[@aria-label='Close' and @role='button]"))).click()
您需要导入以下库
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.