我正在为我的网站自动上传文件。我使用的是FF 31,selenium 2.39。我看到的问题是用下面的java代码上传的文件在Chrome 37上可以工作,但在FF 31上不能工作。我尝试将其用于FF 28-31版本的selenium 43和selenium 39,但没有结果。然后,我添加了内联样式,不透明度从0设置为1,因为输入元素的样式不可见,使用javascript.After执行javascript,我打印出特征。我看到该元素已启用并显示,并且不透明度设置为1,这就是我应用的所有更改。尽管如此,我的sendKeys()似乎不能与it.Although一起工作,我确实想到了AutoIT,我不想添加另一个工具,也不想给自己带来更多麻烦(我的站点/selenium/browser/autoit之间的兼容性问题).Can你们能建议我做些什么来解决这个问题吗?
WebElement input = driver.findElement(By.xpath("//input[@id='img']"));
input.sendKeys("C:/Pictures/img1.gif");
final JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('img').style.opacity=\"1\";");
<i class="coral-Icon">
<input id="img" class="FileUpload" type="file" onchange="preview();" data-upload-url="URL" name="file">
</i>
System.out.println("enabled??== " + input.isEnabled()+ " === "+ input.isDisplayed()+" style "+ input.getAttribute("style"));
console-output : enabled??== true === true style opacity: 1;发布于 2015-06-18 02:09:31
这是我使用的windows m/c上的路径错误。我添加了一个基于OS运行的检查函数,用于更改文件的路径。
String imgPath = imagePath.replaceAll("/","\");
https://stackoverflow.com/questions/26306255
复制相似问题