2014-10-10 139 views
0

我正在为我的网站自动化文件上传。我使用FF 31,硒2.39。我看到的问题是使用下面的java代码的文件上传在Chrome 37上工作,但在FF 31上无法工作。 我试图使用selenium 43和selenium 39来处理FF 28-31版本,所以没有结果。然后我添加了不透明度的内联样式,从0开始设置为1,因为输入元素的样式不可见使用javascript。执行javascript后,我打印出特性。我看到该元素已启用并显示,并将不透明度设置为1,这就是我应用的所有更改。尽管我确实想到了AutoIT,但我并不想为自己添加其他工具并为自己购买更多麻烦(我的网站/ selenium/browser/autoit之间的兼容性问题)。您可以向我们推荐一些东西我可以解决这个问题吗?sendkeys不起作用用于文件输入selenium 2.39 Firefox 31

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; 

回答

0

这是我使用的Windows m/c上的路径错误。我添加了一个基于操作系统的检查函数来改变文件的路径。

String imgPath = imagePath.replaceAll(“/”,“\\”);