我正在使用Selenium 3.141.5,并且尝试运行以下脚本,但是它给我以下错误“ FluentWait类型不是通用的;不能使用参数对其进行参数设置”。请参阅下面的我的脚本。
FluentWait等待=新的FluentWait(驱动程序)
请提前告知并感谢您的帮助。
package Selenium_Assertions_Exercises;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.FluentWait;
public class FluentWait {
public static WebDriver driver;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
// launch Chrome and redirect it to the Base URL
driver.get("http://softwaretestingplace.blogspot.com/2017/02/selenium-
fluent-wait.html" );
//Maximizes the browser window
driver.manage().window().maximize() ;
driver.findElement(By.xpath("//button[text()='Click Me - Fluent
Wait']")).click();
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement element = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
WebElement element = driver.findElement(By.xpath("//*
[@id='softwareTestingMaterial']"));
String getTextOnPage = element.getText();
if(getTextOnPage.equals("Software Testing Material - DEMO PAGE")){
System.out.println(getTextOnPage);
return element;
}else{
System.out.println("FluentWait Failed");
return null;
}
}
});
}
}