【问题标题】:Selenium Hidden File upload in Drag Drop UI拖放 UI 中的 Selenium 隐藏文件上传
【发布时间】:2014-09-12 11:01:40
【问题描述】:

我正在尝试使用 selenium web-driver 在以下输入中添加图像。

<input type="file" multiple="multiple" class="dz-hidden-input" accept="image/gif,image/jpg,image/jpeg,image/png,application/zip" style="visibility: hidden; position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;">

当使用 sendKeys 时,它会给出 ElementNotVisible:元素当前不可见,因为可见性被隐藏。

尝试使用 Java 脚本设置值执行它给 web 驱动程序异常说“操作不安全”。

我发现this已关闭的问题与我的类似。

试过了:

executor.executeScript("arguments[0].style.visibility='visible';",fileInput);

executor.executeScript("arguments[0].style.display='block';", fileInput);

启用可见性但发送密钥失败并出现同样的错误。

我发现了类似的问题Uploading a file through selenium but file input element is hidden,但我的元素永远不会变得可见。

我尝试使用 selenium IDE,它使用 type 命令。

如果有人遇到过同样的问题以及如何解决的,请告诉我。

提前致谢

【问题讨论】:

    标签: javascript selenium-webdriver


    【解决方案1】:

    尝试将 Input 元素的 Opacity 设置为 1,然后使用 SendKeys 提供文件路径。可以使用以下代码设置不透明度:

    executor.executeScript("arguments[0].style.visibility='visible';",fileInput);
    executor.executeScript("arguments[0].style.height='200px';",fileInput);   
    executor.executeScript("arguments[0].style.width='200px';",fileInput);
    

    然后执行 sendKeys 方法。

    如果有帮助,请告诉我!

    【讨论】:

    • 我试过这个但没有工作:信息 - 完成:[执行脚本:参数[0].style.opacity='1';,[[[FirefoxDriver:LINUX上的Firefox(62d69895-4ab1- 4598-b552-425ea7c13e77)] -> xpath: //input[@type='file'][1]]]] 信息 - 执行: [发送密钥: 50 [[FirefoxDriver: LINUX 上的 firefox (62d69895-4ab1-4598) -b552-425ea7c13e77)] -> xpath: //input[@type='file'][1]], [/data1/vishal/svn/9.0.0/automation/selenium/client/dataupload//content_library// images//nature.gif]]) WARN - 抛出异常 org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互
    【解决方案2】:

    如果您在针对 dz-hidden-input 在一个页面上使用多个放置区时遇到问题,您应该这样做:

      init: function() {
        this.hiddenFileInput.className = "dz-hidden-input dz-hidden-input-one";
      }
    

    然后您可以使用 $(".dz-hidden-input-one") 定位隐藏输入

    【讨论】:

      猜你喜欢
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 2012-01-21
      相关资源
      最近更新 更多