Upload Image - Item is not currently displayed
I am trying to upload an image to a site.
I am using for this Selenium 2.45.0
. The following code should load the photo:
public void uploadPhoto(String filePath) {
filePath = filePath.replace("\\", "/");
WebElement fileInput = driver.findElement(By.xpath("//div[@class='qq-upload-button']/input[@type='file']"));
fileInput.sendKeys(filePath);
}
I am using the following browser:
public WebDriver driver = new FirefoxDriver();
public JavascriptExecutor jse = (JavascriptExecutor)driver;
However, I am getting the following exception:
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 66 milliseconds
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'PC', ip: '197.368.536.12', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=38.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: fdfdf84b-4a99-4c47-bf88-b12518172011
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at quotePictureCreator.util.SeleniumUtility.uploadPhoto(SeleniumUtility.java:62)
at quotePictureCreator.main.RunApp.main(RunApp.java:50)
Caused by: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'PC', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.visible(file:///C:/Users/AppData/Local/Temp/anonymous8332268915894898913webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:9587)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/AppData/Local/Temp/anonymous8332268915894898913webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12257)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/AppData/Local/Temp/anonymous8332268915894898913webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12274)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/AppData/Local/Temp/anonymous8332268915894898913webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12279)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/AppData/Local/Temp/anonymous8332268915894898913webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12221)
Any suggestion what I am doing wrong? I appreciate your answers!
+2
source to share