我们可以在selenium webdriver中使用循环的场景是什么? [关闭]

问题描述 投票:-5回答:1

自动化测试中for循环的主要用途是什么(Selenium Webdriver?

java selenium-webdriver
1个回答
2
投票

您可以使用for循环对一组对象进行迭代。 Selenium中的方法数返回一组对象。您将使用for循环迭代它们并在循环体内执行必要的逻辑。

例如,WebDriver有以下方法:java.util.List<WebElement> findElements(By by)

您可以使用for循环迭代返回的WebElements的List,并在循环体内执行必要的操作。

for循环的一个小例子:

// Line below returns a `List` of `WebElements`
List<WebElement> rows = driver.findElements(By.xpath("//table/tr"));

// For loop follows
for (int i = 0; i < rows.size(); i++) {
    // Access individual elements this way:
    WebElement currentRow = rows.get(i);
    // Perform an action with currentRow here
}
© www.soinside.com 2019 - 2024. All rights reserved.