Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么可以';我找不到';功能';webDriver中的函数?_Java_Selenium_Webdriver - Fatal编程技术网

Java 为什么可以';我找不到';功能';webDriver中的函数?

Java 为什么可以';我找不到';功能';webDriver中的函数?,java,selenium,webdriver,Java,Selenium,Webdriver,我想在webdriver下实现一个简单的waitForXX 代码非常简单 Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) { return new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return

我想在webdriver下实现一个简单的waitForXX

代码非常简单

Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {

    return new Function<WebDriver, WebElement>() {

        public WebElement apply(WebDriver driver) {

            return driver.findElement(locator);

        }

    };
定位元件的功能显示(最终由定位器确定){
返回新函数(){
公共WebElement应用(WebDriver){
返回驱动程序findElement(定位器);
}
};
}

但它仍然给我带来麻烦,因为我似乎无法导入“功能”部分

我看了selenium.support.ui下的每个地方,我想它应该在哪里?但我似乎找不到它

我尝试使用最新的Selenium独立jar文件2.5.0


谢谢

似乎来自于。有番石榴罐头吗

似乎来自于。有番石榴罐头吗

不幸的是,我不知道如何在Java中实现这一点,但是您已经看过WebDriver中的WebDriverWait类了吗?它应该可以实现您想要的功能

该类位于Java绑定的支持部分

了解如何在这些测试中使用它

或者可以使用隐式等待

driver.manage().timeouts().implicitlyWait(3000, MILLISECONDS);
driver.findElement(By.id('foo')); //will wait 3 seconds, if not loaded will throw an exception

不幸的是,我不知道如何在Java中做到这一点,但是您已经看过WebDriver中的WebDriverWait类了吗?它应该做您想做的事情

该类位于Java绑定的支持部分

了解如何在这些测试中使用它

或者可以使用隐式等待

driver.manage().timeouts().implicitlyWait(3000, MILLISECONDS);
driver.findElement(By.id('foo')); //will wait 3 seconds, if not loaded will throw an exception

为什么不使用继承自
函数的
org.openqa.selenium.support.ui.ExpectedCondition
?为什么不使用继承自
函数的
org.openqa.selenium.support.ui.ExpectedCondition
?有趣。我不想含蓄地等待。那从来都不是一件好事。但是期望状态部分真的很吸引人。很有趣。我不想含蓄地等待。那从来都不是一件好事。但是ExpectedCondition部分非常吸引人。我给你一个+1,因为这也是一个好主意!谢谢你的评论!我给你一个+1,因为这也是个好主意!谢谢你的评论!