硒:模式内容中的按钮不可单击 [英] Selenium: Button in modal content is not clickable

查看:59
本文介绍了硒:模式内容中的按钮不可单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在硒测试期间单击确定"按钮,但是元素不可见.

I want to Click the "OK" button during a Selenium test but the Element is not visible.

 driver.findElement(By.xpath("//*[@id=\"5f6e7b16-0fa1-4db6-869b-3a6ba6b0fafe\"]")).click();

<div class="bootstrap-dialog-footer-buttons">
    <button class="btn btn-default" id="5a4bb849-7a61-4603-9ef2-f9e0ecab4523">
        <span class="glyphicon glyphicon-ban-circle"></span> Cancel
    </button>
    <button class="btn btn-warning" id="f7f4b18b-2ba2-4c1e-b541-a254c080f398">
        <span class="glyphicon glyphicon-ok"></span> Ok
    </button>
</div>

推荐答案

我认为在您的DOM中,按钮ID是动态变化的.每当页面重新加载时,都会生成新的ID.您在Selenium代码和HTML中使用了不同的按钮ID.因此,我建议您使用 className .尝试下面的代码,希望它对您有用.

I think in your DOM, the button id is changing dynamically. Whenever page reload it will generating new id. There is different button id you used in your Selenium code and HTML. So, I suggest you go with className. Try below code and hope it works for you.

        //If the Element is not visible then wait until that element is not visible
        new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.className("btn btn-warning")));

        //If the element is visible but not Clickable then wait until that element get Clickable.       
        new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.className("btn btn-warning")));

        //Then simply click the button
        driver.findElement(By.className("btn btn-warning")).click();

这篇关于硒:模式内容中的按钮不可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆