我需要使用Selenium webdriver处理对话框处理的帮助。这是firebug中的html for对话框
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all xx_form_dialog ui-draggable ui-resizable ui-dialog-buttons"
style="outline: 0px none; z-index: 20012; position: absolute; height: auto; width: 300px; top: 166.997px; left: 734px; display: block;"
tabindex="-1" role="dialog" aria-labelledby="ui-id-27">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button id="information-ok" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false">
<span class="ui-button-text">OK</span>
</button>
</div>
</div>
</div>
<div>
这就是我的尝试:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[17]"))).click();
driver.findElement(By.id("information-ok")).click();
答案 0 :(得分:0)
public void aLert()
{
boolean a = false;
try {
Alert alert = driver.switchTo().alert();
String AlertText = alert.getText();
System.out.println(AlertText);
alert.accept();
a = true;
} catch (Exception e) {
a = false;
}finally {
if (a != true) {
// take ur screenshot or whatever
driver.findElement(By.id("information-ok")).click();
}
}
}