我正在尝试为我工作的公司自动化前端网站,但是我在尝试找到此xpath时遇到问题,当我在pyhton中运行测试用例时,我得到以下内容:
"Selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/lc-app/lc-auth-app/top-menu-bar/div/div[2]/top-menu-bar-right-section/div/top-menu-bar-right-section-drop/div/div[2]/ul/li[2]/button/span "}"
********这是我目前拥有的xpath,请看下面****
*"/html/body/div/lc-app/lc-auth-app/top-menu-bar/div/div[2]/top-menu-bar-right-section/div/top-menu-bar-right-section-drop/div/div[2]/ul/li[2]/button/span"*
我能找到这个特定的 xpath 吗?我已经附上了我试图找到的图片。"活动"路径,我需要具体,但我无法让它工作活动 xpath
尝试以下Xpath
。
//button[@class='top-menu-drop-link']/span[text()='Activity']
蟒蛇代码:
driver.find_element_by_xpath("//button[@class='top-menu-drop-link']/span[text()='Activity']").click()
但是,最佳做法是使用WebDriverWait
和element_to_be_clickable
((
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='top-menu-drop-link']/span[text()='Activity']"))).click()
注意:要执行WebDriverWait,您需要导入以下内容。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC