我需要通过Selenium webdriver上传文件。 但如果我使用类似:如何删除标签<input type =“file”>中的属性“
driver.findElement(By.xpath("//input[@type='file']")).sendKeys(file.getAbsolutePath());
然后我得到了一个错误:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 128 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
所以我想我需要删除使用js的隐藏属性,我发现这个代码:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementsByTagName('*')[0].removeAttribute('hidden');");
但它不适合我。
这是我工作的代码:
<label name="file" ng-model="file" ngf-accept="pattern" ngf-pattern="pattern" ngf-select="uploadSubmit($file)" ng-disabled="isUploadDisabled()" type="button" class="button button--large ng-pristine ng-untouched ng-valid ng-empty">
<span translate="" class="button__text">Загрузить из файла .xls</span>
<input type="file" hidden="" ng-disabled="isUploadDisabled()">
</label>
我添加的代码的一部分,你可以请我的情况格外 –
我已经更新了我的回答,我已经检查,然后张贴所以请关心这个 – Jigar7521