'Cannot resolve method 'setFileDetector' in 'WebDriver' in Java
As per this, https://www.selenium.dev/documentation/webdriver/remote_webdriver/
I'm trying to set it up my Remote webdriver with this option, by using webdrivermanager by bonigarcia and I use below code.
import org.openqa.selenium.remote.LocalFileDetector;
//From a customzed method I get remote BrowserStack chrome instance.
WebDriver driver= WebDriverFactory.getDriver();
driver.setFileDetector(new LocalFileDetector());
But I get Cannot resolve method 'setFileDetector' in 'WebDriver. Please help.

Solution 1:[1]
I suppose you should use RemoteWebDriver instead of WebDriver
Solution 2:[2]
The best option to explore such error is to check public API docs, to make sure you use the right interface. RemoveWebDriver interface owns this method, WebDriver is not.
So the solution would be to revise the construction of driver and make sure RemoteWebDriver instance is returned.
// WebDriver driver = WebDriverFactory.getDriver();
RemoteWebDriver driver = /* Use Selenium docs to construct the object */;
Solution 3:[3]
This code worked for me to run the test in BrowserStack.
WebElement uploadFile = driver.findElement(By.xpath("//input[@type='file']"));
((RemoteWebElement)uploadFile).setFileDetector(new LocalFileDetector());
upload_file.sendKeys(System.getProperty("user.dir")+"/src/main/java/resources/common/<Name of your file>.csv");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexzander Zharkov |
| Solution 2 | udalmik |
| Solution 3 | fahim reza |
