gpt4 book ai didi

java - 上传图片 - 元素当前不可见

转载 作者:行者123 更新时间:2023-11-30 11:03:28 25 4
gpt4 key购买 nike

我正在尝试将图片上传到网站。

为此,我正在使用 Selenium 2.45.0。以下代码应上传照片:

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;

但是,我得到以下异常:

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)

有什么建议我做错了吗?感谢您的回复!

最佳答案

降级 firefox 可能会有帮助。到目前为止,我将它与 firefox 34 和 chrome 43 一起使用,按预期工作。 但是,隐藏文件标签不适用于 IE。参见 thisthis

关于java - 上传图片 - 元素当前不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com