小编Shi*_*ino的帖子

明确等待Selenium Webdriver中的findElements

登录后,页面将重定向到一个页面(我想等待页面加载),在这里我通过tagName查找元素,

By inputArea = By.tagName("input");
 List <WebElement> myIput = driver.findElements(inputArea);
Run Code Online (Sandbox Code Playgroud)

在这里,我想给Explicit Wait等待findElements,我要等待它的所有可见性或存在性。我的网页中只有两个输入。如果我让隐式等待时间很长,代码将起作用。但这有所不同。因此,我决定给Explicit Wait,如何给露骨的Wait for findElements?或如何从列表(列表myIput)中检查第二个的可见性。即myIput.get(1)。当我像下面这样给可视性OfAllElements()时,它将引发错误。

WebDriverWait waitForFormLabel = new WebDriverWait(driver, 30);      
By inputArea = By.tagName("input");
List <WebElement> myIput = driver.findElements(inputArea);
waitForFormLabel.until(ExpectedConditions.visibilityOfAllElements(myIput));
myIput.get(1).sendKeys("Test");
Run Code Online (Sandbox Code Playgroud)

这是我在自动化程序中使用的代码列表。

package mapap;
import java.util.ArrayList;
import java.util.List;

import lib.ReadExcellData;
import lib.WriteExcellData;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class EditForm {
    public static WebDriver driver;
    static String excelName         = "D:\\xlsx\\map2.xlsx"; …
Run Code Online (Sandbox Code Playgroud)

selenium selenium-webdriver

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

selenium ×1

selenium-webdriver ×1