user1935987 user1935987 - 1 year ago 155
Java Question

Selenium RemoteWebDriver FileDetector Java

I have a problems with the file upload through Selenium

(chrome driver, up using selenium grid).

Similar to this thread: Sending Keys to Input WebElement fails as it is not an absolute path

Done some research and seems like that solution works. However, i'm getting this error:
Cannot resolve method 'setFileDetector(org.openqa.selenium.remote.LocalFileDetector)'

I did have a required imports.
Here is my remote webdriver setup method:

public WebDriver SetupRemoteChromeDriver(){

Integer pageTimeout = 50;

final DesiredCapabilities capabilities = new DesiredCapabilities();

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"),

//File upload issue specific to chromedriver
browser.setFileDetector(new LocalFileDetector());
} catch (MalformedURLException e) {

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.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.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;

selenium version: 2.53.1
According to the docs
class must have that method. Any idea why it's not imported?

Answer Source

I think you need to change line WebDriver browser = null; to RemoteWebDriver browser = null;. The variable browser is defined with type WebDriver which does not have the specified method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download