[英]Selenium RemoteWebDriver FileDetector Java
I have a problems with the file upload through Selenium RemoteWebDriver
(chrome driver, up using selenium grid). 通过Selenium
RemoteWebDriver
(Chrome驱动程序,使用selenium网格)上传文件时出现问题。
Similar to this thread: Sending Keys to Input WebElement fails as it is not an absolute path 与此线程类似: 向输入WebElement发送键失败,因为它不是绝对路径
Done some research and seems like that solution works. 做了一些研究,似乎解决方案有效。 However, i'm getting this error:
Cannot resolve method 'setFileDetector(org.openqa.selenium.remote.LocalFileDetector)'
但是,我收到此错误:
Cannot resolve method 'setFileDetector(org.openqa.selenium.remote.LocalFileDetector)'
I did have a required imports. 我确实有一个必需的进口。 Here is my remote webdriver setup method:
这是我的远程webdriver设置方法:
public WebDriver SetupRemoteChromeDriver(){
Integer pageTimeout = 50;
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("acceptSslCerts",true);
capabilities.setCapability("cssSelectorsEnabled", false);
capabilities.setCapability("applicationCacheEnabled", true);
capabilities.setCapability("handlesAlerts", true); //this is new to try
capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
WebDriver browser = null;
try {
browser = new RemoteWebDriver(
new URL("http://*ip*:4444/wd/hub"),
capabilities
);
//File upload issue specific to chromedriver
browser.setFileDetector(new LocalFileDetector());
} catch (MalformedURLException e) {
e.printStackTrace();
}
browser.manage().timeouts().pageLoadTimeout(pageTimeout, TimeUnit.SECONDS);
browser.manage().timeouts().setScriptTimeout(pageTimeout, TimeUnit.SECONDS);
browser.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
return browser;
}
imports to that class: 导入到该类:
import com.gargoylesoftware.htmlunit.BrowserVersion;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;
selenium version: 2.53.1 According to the docs https://seleniumhq.github.io/selenium/docs/api/java/ RemoteWebDriver
class must have that method. selenium版本:2.53.1根据文档https://seleniumhq.github.io/selenium/docs/api/java/
RemoteWebDriver
类必须具有该方法。 Any idea why it's not imported? 知道为什么不进口吗?
I think you need to change line WebDriver browser = null;
我认为你需要更改行
WebDriver browser = null;
to RemoteWebDriver browser = null;
到
RemoteWebDriver browser = null;
. 。 The variable
browser
is defined with type WebDriver
which does not have the specified method. 变量
browser
使用类型WebDriver
定义,该类型没有指定的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.