我想使用selenium远程上传文件。
我的代码在Chrome
上正常运行,但未在Firefox
上抛出以下错误。
**org.openqa.selenium.UnsupportedCommandException: Unrecognized command: POST /session/a759b398-2adf-8343-8575-7c156f389289/file
Command duration or timeout: 6 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'Vaibhav.local', ip: '172.20.57.75', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=MAC, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=false, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: a759b398-2adf-8343-8575-7c156f389289
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)**
我正在使用Firefox
和Selenium
的最新版本。
答案 0 :(得分:0)
如果您正在运行远程实例,则可能需要设置文件检测器:
driver.setFileDetector(new LocalFileDetector());
WebElement element = driver.findElement(By.cssSelector("input[name='file']");
element.sendKeys("Path to file");