Are you able to upload a file [duplicate]

2019-09-07 20:14发布

问题:

This question already has an answer here:

  • How to upload file in angularjs e2e protractor testing 8 answers

I have a test that I would like to upload pictures to a website that uses the defaulted OS upload modal. After I click upload I cannot access the upload screen. Is there a way around it? I saw online that it looked like there was but I had no idea how to implement what they were saying.

element(By.xpath("//div[@id='ngdialog28']/div[2]/div/div[6]/div/span")).click()
element(By.css("input[type=\"file\"]")).click();
element(By.css("input[type=\"file\"]")).clear();
element(By.css("input[type=\"file\"]")).sendKeys("C:\\ProgramData\\MeetingMatrix International\\MeetingMatrix 2010\\MMIDEMO\\Setups\\Test.mms");

回答1:

The answer below came from a previous post I had overlooked. Here is the code:

var path = require('path');

var fileToUpload = 'Put the path here',
  absolutePath = path.resolve(__dirname, fileToUpload);

$('input[type="file"]').sendKeys(absolutePath);