【问题标题】:Not able to upload file due to error "WebDriverError: Element is not reachable by keyboard" in Firefox browser由于 Firefox 浏览器中的错误“WebDriverError:键盘无法访问元素”而无法上传文件
【发布时间】:2018-09-17 12:21:54
【问题描述】:

我正在使用量角器版本 5.2.2。 , geckodriver-v0.21.0 和 Firefox 浏览器版本 61。当我尝试在 Firefox 浏览器中运行量角器脚本时,它显示错误为

"WebDriverError:Element  <input id="logo" class="frx-input-file" name="logo" 
 type="file">is not reachable by keyboard.
   Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:
 32:19.891Z'
   System info: host: 'CS-COK-DEV-039', os.name: 'Windows 8.1', os.arch: 
'amd64', os.version: '6.3', java.version: '1.8.0_60'
   Driver info: driver.version: unknown".   

量角器码是

var path = require('path');
var fileToUpload = "F://images/f2.jpg";
var absolutePath = path.resolve(__dirname, fileToUpload);
element(by.css('.frx-form-section-container .frx-client-logo-field .frx-input-file')).sendKeys(absolutePath);

UI代码是

<div _ngcontent-c6="" class="frx-form-input-field-container frx-client-logo- 
field">
  <label _ngcontent-c6="" class="frx-input-file-label" for="logo">Upload 
  logo</label>
  <br _ngcontent-c6="">
  <span _ngcontent-c6="" class="frx-input-file-caption" for="logo">Will be 
   used on the templates and letters</span>
  <input _ngcontent-c6="" accept=".jpg, .jpeg, .gif .JPG, .JPEG, .GIF, .BMP 
   ,.bmp" class="frx-input-file" id="logo" multiple="false" name="logo" 
   type="file">
</div>

相同的量角器脚本在 chrome 和 IE 浏览器中都成功运行。我们如何在 Firefox 中解决此问题。提前致谢

【问题讨论】:

    标签: protractor


    【解决方案1】:

    以下代码在 Firefox、Chrome 和 IE 中成功地为我工作。

    var path = require('path');
    //use your file's path
    var fileToUpload = "../files/helthplan.png";
    var absolutePath = path.resolve(__dirname, fileToUpload);
    //use your application's locator for upload input file.
    var fileElem = element(by.css(".frx-form-section-container .frx-client-logo-field .frx- input-file"));
    browser.executeScript("arguments[0].style.display = 'inline';", 
    fileElem.getWebElement());
    element(by.css('input[type="file"]')).sendKeys(absolutePath);
    

    【讨论】:

      【解决方案2】:

      直接连接:假,

      { browserName: 'firefox', 'moz:webdriverClick': false }

      设置这些属性在您的配置文件中输入将解决问题的代码。

      【讨论】:

        猜你喜欢
        • 2023-01-12
        • 2021-06-15
        • 1970-01-01
        • 2018-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多