量角器图像没有在对话框上传?

问题描述 投票:0回答:1

我想使用Protractor测试图像上传功能,但我的书面脚本没有用。 This is the image dialogue box.当我们点击对话框图像时,它打开窗口选择所需的图像。选择图像后,框就像这样image。我想写一个脚本,通过它我可以上传图像,然后点击“保存“button.This is the css of dialogue box.下面给出的是我尝试但不起作用的脚本。遇到的错误消息是this

   var path = require('path');
   var fileToUpload = '../new image.jpeg';
    var absolutePath = path.resolve('__dirname', fileToUpload);
    console.log(absolutePath);
 var fileElem=element(by.css('label[for="cropper-file-input"]'));
 browser.wait(EC.presenceOf(fileElem), 2000,);
 fileElem.sendKeys(absolutePath);
css angular selenium jasmine protractor
1个回答
0
投票

尝试以下方法。希望它可以帮到你。

 fileUpload(element: ElementFinder, fileElem: ElementFinder, filePath: string): promise.Promise<void> {
        //We are using the setFileDetector method to let WebDriver know that we are uploading files from a local directory to a remote server.
        //Having this configuration resolves the "Failed: invalid argument: File not found" error that occurs otherwise.
        browser.driver.setFileDetector(new utils.remote.FileDetector);

        return browser.executeScript(`arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px';  arguments[0].style.opacity = 1`, element)
            .then(() => fileElem.sendKeys(filePath));
    }
© www.soinside.com 2019 - 2024. All rights reserved.