Reputation: 137
I am trying to upload a file but no succes, I found this example:
WebElement element = getSupport().getDriver().findElement(By.xpath(".//input[@type='file']"));
element.sendKeys("D:/Profiles/user/workspace/copla-selenium/src/test/resources/datasets/default/test-image.jpg");
But I get this error:
2015-02-23 17:32:59 ERROR root:97 - Test failed org.openqa.selenium.WebDriverException: unknown error: cannot focus element
Any idea? Thanks!
Upvotes: 0
Views: 363
Reputation: 1217
Are you using webdriver , If yes then sendKeys never works for webdriver. If you want to use webdriver then try autoIt or robot class for file uploading. Otherwise you can use remote webdriver Like this:
RemoteWebDriver rdriver = new RemoteWebDriver(caps);
rdriver.setFileDetector(new LocalFileDetector());
WebElement element = rdriver.findElement(By
.xpath(".//input[@type='file']"));
element.sendKeys("D:/Profiles/user/workspace/copla-selenium/src/test/resources/datasets/default/test-image.jpg");
Upvotes: 1