twitter-bootstrap - 无法访问 Selenium Webdriver 中的 Bootstrap 模式对话框

标签 twitter-bootstrap selenium

我想要访问打开的模型对话框的内容,并且想要访问按钮(是、否)。

这是 HTML 代码,如下所示

<div class="modal-dialog">
<div class="modal-content">
    <div class="modal-header"><div class="bootstrap-dialog-header">
        <div class="bootstrap-dialog-close-button" style="display: none;">
            <button class="close">×</button>
        </div>
        <div class="bootstrap-dialog-title" id="e6adf6aa-dcbf-4fb8-9935-c083762f2812_title">
        Inactivate user
        </div>
    </div>
</div>
<div class="modal-body">
    <div class="bootstrap-dialog-body">
        <div class="bootstrap-dialog-message">
        Are you sure you want Inactivate user?
        </div>
    </div>
</div>
<div class="modal-footer">
    <div class="bootstrap-dialog-footer">
        <div class="bootstrap-dialog-footer-buttons">
            <button class="btn btn-default" id="868d2d8a-67f6-4308-a3c8-0246a5d4618c">Yes</button>
            <button class="btn btn-default" id="23e4d027-ef32-4b58-b8b6-6f95bead2db4">No</button>
        </div>
    </div>
</div>

还有一件事是按钮的 ID 是动态的。

最佳答案

经过大量谷歌搜索后,我找到了解决方案......这是一个简单的解决方案

//Switch to active element here in our case its model dialogue box.
driver.switchTo().activeElement();

Thread.sleep(3000);

// find the button which contains text "Yes" as we have dynamic id
driver.findElement(By.xpath("//button[contains(text(),'Yes')]")).click();

这段代码解决了我的问题。

关于twitter-bootstrap - 无法访问 Selenium Webdriver 中的 Bootstrap 模式对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32861422/

相关文章:

javascript - jQuery 不工作(ReactJS、Bootstrap、Webpack)

java - 使用带有 Java 的 Selenium WebDriver 在新页面上查找 WebElement

python - 全局名称未定义 - python

html - Bootstrap 容器

html - 如何将列内容放在底部?

python - Selenium Python : Unable to locate element

java - 如何打印定位器路径

java - 无论如何,有没有使用 selenium 在单个脚本中混合 ios 自动化和 Web 自动化

html - 移动 View 中右侧的空白

javascript - 如何在页面加载时添加类之前确保元素已加载