无法访问 Selenium Webdriver 中的引导模式对话框 [英] Not able to access bootstrap modal dialog in Selenium Webdriver

查看:40
本文介绍了无法访问 Selenium Webdriver 中的引导模式对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

HTML 代码如下

<div class="bootstrap-dialog-title" id="e6adf6aa-dcbf-4fb8-9935-c083762f2812_title">停用用户

<div class="modal-body"><div class="bootstrap-dialog-body"><div class="bootstrap-dialog-message">您确定要停用用户吗?

<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">是</button><button class="btn btn-default" id="23e4d027-ef32-4b58-b8b6-6f95bead2db4">否</button>

还有一件事是按钮的 id 是动态的.

解决方案

经过如此多的谷歌搜索,我找到了解决方案......这里是这个问题的简单解决方案

//在我们的例子中切换到活动元素的模型对话框.driver.switchTo().activeElement();线程睡眠(3000);//找到包含文本是"的按钮,因为我们有动态 IDdriver.findElement(By.xpath("//button[contains(text(),'Yes')]")).click();

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

I want to Access the content of the model dialog box open, and want to access buttons (Yes,No).

Here is HTML code looks like

<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>

One more thing is id of the buttons are dynamic.

解决方案

I found the solution for this after so much googling... here is the simple solution for this

//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();

This code solves my problem.

这篇关于无法访问 Selenium Webdriver 中的引导模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆