Upload file to hidden input using protractor and selenium

后端 未结 2 2033
眼角桃花
眼角桃花 2021-01-20 05:22

I\'ve got a hidden file input field like this:



        
2条回答
  •  失恋的感觉
    2021-01-20 06:03

    The only way I could find to do this in the end was to use javascript to make the input element visible.

    So I have a function unhideFileInputs:

      var unhideFileInputs = function () {
        var makeInputVisible = function () {
          $('input[type="file"]').removeClass('hidden-uploader');
        };
    
        ptor.driver.executeScript(makeInputVisible);
      }
    

    This contains the function 'makeInputVisible' which is executed in the browser when I call ptor.driver.executeScript(makeInputVisible). Because I know my page contains jQuery I can use the jQuery removeClass method to unhide my file input element.

    To see more on how to execute javascript in the browser using webdriver, see the answer to this question (although the answer uses executeAsyncScript rather than executeScript).

提交回复
热议问题