[英]Protractor image upload doesn't work on IE and firefox
我正在嘗試使用量角器在輸入type:file控件上上傳圖像。
我正在使用以下代碼:
var basePath='../testdata/testappicons/accepted';
var randomIcon=randomIntFromInterval(1,6);
var overallPathToIcon=basePath+randomIcon+'.png';
var fileToUpload = overallPathToIcon;
console.log(fileToUpload);
var absolutePath = path.resolve(__dirname, fileToUpload)
browser.executeScript('$(\'input[type="file"]\').attr("style", "");');
$('input[type="file"]').sendKeys(absolutePath);
上面的代碼在chrome上運行良好,我能夠上傳文件,但是當我在firefox和IE上使用相同的代碼時。 我收到以下錯誤:
ElementNotVisibleError:不顯示元素
這是表單的HTML:
div class="fileUpload" ng-click="IsInValid=true">
<label class="btn btn-white uploadBtn" title="Upload image file" for="upload-image">
<input id="uploadFile" type="text" readonly="" placeholder="Browse new app icon" value="maxsizepngfile.png">
<input id="upload-image" class="upload ng-pristine ng-untouched ng-valid ng-isolate-scope" type="file" ng-model="image" image="appicon" accept="image/*">
</label>
<label class="btn btn-warning" for="upload-image">
<span>Browse</span>
</label>
</div>
我的猜測是,因為它是只讀的,所以它不起作用。 誰能幫我這個忙嗎?
這是為我工作的代碼
var basePath='../testdata/testappicons/accepted';
var randomIcon=randomIntFromInterval(1,6);
var overallPathToIcon=basePath+randomIcon+'.png';
var fileToUpload = overallPathToIcon;
console.log(fileToUpload);
var absolutePath = path.resolve(__dirname, fileToUpload)
//browser.executeScript('$(\'input[type="file"]\').attr("style", "");');
var elm = $('input[type="file"]'); // protractor's shortcut to element(by.css("css"))
//browser.executeScript('var input = $("input:file"); var elm = input[0];elm.style.visibility = "visible"; elm.style.height = "1px"; elm.style.width = "1px";elm.style.opacity = 1;');
browser.executeScript('var input = $("input:file"); input[0].removeAttribute("class");');
elm.sendKeys(absolutePath);
仍然是一種猜測,但是是有教養的:不要在設置style
涉及jQuery:
var elm = $('input[type="file"]'); // protractor's shortcut to element(by.css("css"))
browser.executeScript('arguments[0].style = {};', elm.getWebElement());
elm.sendKeys(absolutePath);
此外,要遵循@dmitankin的評論和WebDriver是否支持文件上傳? 常見問題解答部分,請嘗試通過以下方式使元素可見:
function makeVisible(arguments) {
var elm = arguments[0];
elm.style.visibility = 'visible';
elm.style.height = '1px';
elm.style.width = '1px';
elm.style.opacity = 1;
}
browser.executeScript(makeVisible, elm.getWebElement());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.