【发布时间】:2017-02-17 05:11:19
【问题描述】:
我正在运行测试,但在管理模式对话框时遇到了意外问题。
用户在模态对话框中上传文件,如果该文件已存在于系统中,则会打开另一个单独的模态对话框,询问用户是否要覆盖现有文件。
我在操作第二个对话框上的按钮时遇到了困难。
当我管理第一个对话框时,我会执行以下操作:
void switch_to_dialog_window(WebDriver driver){
driver.switchTo().frame(driver.findElement(By.cssSelector("div.d2l-dialog>div>iframe")));
}
两个对话框都打开时的 html 如下所示:
<div class="d2l-dialog" style="top: 70px; width: 700px; height: 520px; left: 630px; z-index: 1002;">
<div class="d2l-dialog-inner" style="height: 518px;">
<iframe class="d2l-dialog-frame" src="/d2l/common/dialogs/file/main.d2l?ou=11346&af=MyComputer%2cOuFiles%2cSharedFiles%2cgooglefiledownloader%2coffice365filedownloader&am=1&fsc=1&asc=0&mfs=0&afid=0&uih=&area=MyComputer&f=&path=%2fcontent%2fenforced%2f11346-Gherkin_Cucumber%2f&d2l_body_type=2" name="d2l_c_10_968" allowfullscreen="" scrolling="no" style="width: 698px; height: 518px; overflow: hidden;" frameborder="0"/>
</div>
</div>
<div class="d2l-dialog" style="top: 90px; width: 475px; height: 415px; left: 800px; z-index: 1004; display: block;">
<div class="d2l-dialog-inner" style="height: 413px;">
<iframe class="d2l-dialog-frame" src="/d2l/lp/fileinput/11346/Duplicates?files=photo.jpg" name="d2l_c_1_182" allowfullscreen="" scrolling="no" style="width: 473px; height: 413px; overflow: hidden;" frameborder="0"/>
</div>
</div>
我正在尝试控制提及重复项的对话框。
我尝试将 switch_to_dialog_window 的方法修改为更具体(作为识别第一个对话框来控制它的测试):
driver.switchTo().frame(driver.findElement(By.cssSelector("div.d2l-dialog>div>iframe[src^='/d2l/common/dialogs/file/main.d2l']")));
这不起作用,所以我无法实现这种方式来管理 2 个对话框。
我尝试切换到默认内容,然后使用“switch_to_dialog_window”方法切换回对话框,但这也不起作用。我只是尝试直接访问对话框上的按钮,但这不起作用:
public void confirm_duplicate() {
//driver.findElement(By.xpath("//iframe[starts-with(@src, '/d2l/lp/fileinput/11346/Duplicates')]"));
//driver.switchTo().frame(driver.findElement(By.cssSelector("div>div>iframe[src^='/d2l/lp/fileinput/11346/Duplicates']")));
try{
//driver.switchTo().frame(driver.findElement(By.cssSelector("div>div>iframe[name^='d2l_c_1_']")));
driver.findElement(By.linkText("Update")).click();
}catch(Exception e)
{
System.out.println("could not click on the Update button on the top most dialog box");
e.printStackTrace();
}
}
我似乎在这个圈子里跑来跑去,筋疲力尽。有人能解释一下如何控制这个最顶层的对话框吗?
你也可以教我为什么下面的表达式不起作用:
driver.switchTo().frame(driver.findElement(By.cssSelector("div.d2l-dialog>div>iframe[src^='/d2l/common/dialogs/file/main.d2l']")));
【问题讨论】:
标签: java selenium modal-dialog selenium-chromedriver