Selenium 定位文本为'确认',且标签为button,坐标不为0的元素
可以使用 Selenium 的 find_elements_by_xpath 方法配合 XPath 表达式来定位符合条件的元素。下面是一个示例代码:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://example.com")
elements = driver.find_elements_by_xpath("//button[text()='确认' and @style!='display:none;' and @style!='left: 0px; top: 0px;']")
for element in elements:
print(element.text)
driver.quit()
上述代码中,使用了 XPath 表达式 //button[text()='确认' and @style!='display:none;' and @style!='left: 0px; top: 0px;'] 来定位符合条件的元素:
//button:选择所有button标签[text()='确认']:筛选出文本内容为'确认'的元素[not(@style='display:none;')]:筛选出样式不为'display:none;'的元素[not(@style='left: 0px; top: 0px;')]:筛选出样式不为'left: 0px; top: 0px;'的元素
你可以根据实际情况调整 XPath 表达式的条件。
原文地址: https://www.cveoy.top/t/topic/pk67 著作权归作者所有。请勿转载和采集!