我试图打开弹出对话框,然后输入文件位置上传文件,但执行webdriver时,下面的按钮不可见 .
按钮的顶部参数具有负值(-5000px),当鼠标移动时,此值会相应更改 .
按钮:
<form><iframe onload="ajax.hideLoader();" name="frame_btnUploadImage55c3fefdb188d" style="display:none;"></iframe><input type="file" id="btnUploadImage55c3fefdb188d" name="btnUploadImage55c3fefdb188d" onchange=";ajax.submit('ClickBlocks\\Web\\UI\\POM\\ImgEditor@imgEditor55c3fefda8290->uploadImage_btnUploadImage55c3fefdb188d', 'frame_btnUploadImage55c3fefdb188d')" size="1" onmouseover=";ajax._getFormByTarget('frame_' + this.id); uploadbutton.initialize('btnUploadImage55c3fefdb188d', 0, 0);" style="position: absolute; width: 60px; top: -5000px; z-index: 1; opacity: 0; left: 445px;" runat="server">+ Add</form>
以下是我尝试过的但是得到错误“元素当前不可见,因此可能无法与之交互”:
driver.findElement(By.cssSelector(“input [id ^ ='btnUploadImage']”)) . sendKeys(“C:\ a.png”); driver.findElement(By.xpath( “//输入[@类型= '文件']”))的SendKeys( “C:\ a.png”); . driver.findElement(By.xpath(“// input [text()='Add']”)) . sendKeys(“C:\ a.png”);
任何人都有这种按钮的经验,请帮忙 .
UPDATE: 我找到了如下方法:
WebElement elem = driver.findElement(By.cssSelector(“* [id ^ = btnUploadImage”)); JavascriptExecutor js =(JavascriptExecutor)驱动程序; js.executeScript(“arguments [0] .click();”,elem);
2 回答
由于元素不可见,您必须添加隐式等待:
或者通过添加Webdriver等待:
确保已触发事件以显示弹出窗口 .
通常这些
input[type='file']
是不可见的,为了使其可见,您可以使用javascript