如何使用java selenium处理确认对话框

时间:2015-01-25 08:47:19

标签: java selenium

我试着找出如何点击按钮"停用" 。这是HTML代码:

<div class="ui-widget-overlay" style="width: 1328px; height: 1063px; z-index: 1001;"></div>

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all" style="display: block; z-index: 1002; outline: 0px none; height: auto; width: 640px; top: 737.4px; left: 173px;" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-1">

    <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" unselectable="on" style="-moz-user-select: none;">
        <span id="ui-dialog-title-1" class="ui-dialog-title" unselectable="on" style="-moz-user-select: none;"></span>
        <a class="ui-dialog-titlebar-close ui-corner-all" href="#" role="button" unselectable="on" style="-moz-user-select: none;">
            <span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;"></span>
        </a>
    </div>
    <div class="confirmDialog ui-dialog-content ui-widget-content" style="width: auto; min-height: 134.133px; height: auto;">
        <span class="closeButton"></span>
        <h3></h3>
        <p></p>
        <p></p>
        <div class="buttonRow">
            <button class="negative cancel" type="button"></button>
            <button class="deactivate" type="button"></button>
        </div>
    </div>

</div>

我试图以这种方式点击此按钮:

@FindBy(className = "deactivate")
private WebElement deactivateButton;
WebDriverWait wait =new WebDriverWait(driver,15);
    wait.until(ExpectedConditions.elementToBeClickable(deactivateButton));
 deactivateButton.click();

但这没有帮助

1 个答案:

答案 0 :(得分:0)

请尝试 visibilityOf ,而不是 visibilityToBeClickable ,如下所示。它更干净。:

WebDriverWait wait =new WebDriverWait(driver,20);
    wait.until(ExpectedConditions.visibilityOf(deactivateButton));
 deactivateButton.click();