上传图片 - 元素目前不可见 [英] Upload picture - Element is not currently visible
本文介绍了上传图片 - 元素目前不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图片上传到网站。
I am trying to upload a picture to a site.
我正在使用 Selenium 2.45.0
这个。以下代码应上传照片:
I am using Selenium 2.45.0
for this. The following code should upload a 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);
}
我使用以下浏览器:
public WebDriver driver = new FirefoxDriver();
public JavascriptExecutor jse = (JavascriptExecutor)driver;
但是,我得到以下例外:
However, I get 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 replies!
推荐答案
降级 firefox 可能会有所帮助。直到现在我用firefox 34和chrome 43按预期工作。 但是,隐藏文件标记不适用于IE 。请参见此和这个
Downgrading firefox would help probably. Until now I used that with firefox 34 and chrome 43 works as expected. However, hidden file tag will not work with IE. See this and this
这篇关于上传图片 - 元素目前不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文