当上述路径看起来像这样时,如何增加 img 路径的值?
//ab[x]/img
X 值增加 1,限制为 50。
尝试编写一个关于如何点击网站上的多张图片的测试用例。
编辑:只是想补充一点,我刚开始使用 Selenium IDE 并使用标准命令。
最佳答案
解决方案 1:格式化您的 xpath 路径选择器
for(int i=1; i<=numberOfImages; i++) {
String path = String.format("//ab[%d]/img", i);
WebElement image = driver.findElement(By.xpath(path));
if(image != null) {
image.click();
}
}
解决方案 2:选择“//ab/img”返回的所有元素并对其进行迭代。
String path = "//ab/img";
List<WebElement> imgElements = driver.findElements(By.xpath(path)); //notice the plural
for(WebElement image : imgElements) {
image.click();
}
关于selenium - 使用 Selenium IDE 增加值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33383312/