自动化测试中for循环的主要用途是什么(Selenium Webdriver?
您可以使用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
}