首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sendkeys不适用于File input selenium 2.39 Firefox 31

sendkeys不适用于File input selenium 2.39 Firefox 31
EN

Stack Overflow用户
提问于 2014-10-11 02:58:57
回答 1查看 789关注 0票数 0

我正在为我的网站自动上传文件。我使用的是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你们能建议我做些什么来解决这个问题吗?

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2015-06-18 02:09:31

这是我使用的windows m/c上的路径错误。我添加了一个基于OS运行的检查函数,用于更改文件的路径。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26306255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档