-1
我是selenuim中的新成員。我使用selenuim和xpath selector。我知道如何獲得某個元素。但是如何使用xpath來獲取每個元素5?Selenuim xpath每個元素5
我是selenuim中的新成員。我使用selenuim和xpath selector。我知道如何獲得某個元素。但是如何使用xpath來獲取每個元素5?Selenuim xpath每個元素5
你總是可以用你選擇的語言來解決它。
的Python
例如,在Python,擴展切片allows to do it rather simply:
driver.find_elements_by_xpath("//table/tr")[0::5]
您還可以使用position()
function和mod
操作:
//table/tr[position() mod 5 = 0]
driver.find_elements_by_xpath("//table/tr[position() mod 5 = 0]")
Java
List<WebElement> elements=driver.findElements(By.xpath("//tbody/tr[position() mod 5 = 0]"));
System.out.println(elements.size());
for (WebElement element : elements) {
System.out.println(element.getText());
}
如何從第二個元素開始每5個元素? – user6355594
可以請提供一些像HTML代碼和所有?並提及編程語言 –