[英]SELENIUM FIND ELEMENT BY XPATH
I have three elements with the same button class and span class names .我有三个具有相同按钮 class和跨度 class 名称的元素。 I wanted to use xpath to select the second span class but I always get it wrong.
我想使用 xpath 到 select 第二个跨度 class 但我总是弄错。
I used:我用了:
browser.find_element(By.XPATH, "/html/body/div[1]/div/div[3]/main/div[3]/div[2]/div[2]/div/div/section[2]/div[2]/form/div[9]/button/span[1]").click()
But I get error.但我得到错误。 I also tried the following but get the same error message.
我也尝试了以下但得到相同的错误消息。
result = browser.find_elements(By.XPATH, "//button[@class='_1h5on2Eq5J']")[2].click()
browser.switch_to.frame(result)
results = browser.find_element(By.XPATH, "/html/body/div[1]/div/div[3]/main/div[3]/div[2]/div[2]/div/div/section[2]/div[2]/form/div[9]/button/span[1]")
Below is an excerpt of the html. My interest is to find the second element.下面是html的摘录。我的兴趣是找到第二个元素。
You can use xpath to find text that contains a substring.您可以使用 xpath 查找包含 substring 的文本。
Here's the selector you would want for the "Expand" button:这是您想要的“展开”按钮的选择器:
"//button//span[contains(., 'Expand')]"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.