简体   繁体   English

无法使用Java在Selenium Webdriver中的弹出窗口中单击按钮

[英]Unable to click on a button in Pop-up in Selenium webdriver using java

I am trying to click on a Yes button on a pop-up window in Selenium and not able to do so. 我试图在Selenium的弹出窗口中单击“是”按钮,但无法这样做。 HTML code is : HTML代码是:

<div id="dialoguebuttons">    
    <div style="left: 60px; color: rgb(0, 102, 153); padding-top: 5px; font-size: 16px; font-weight: bold; float: left; position: relative;" id="dialog_question">Activate Riskfirst Rapid?</div>
        <a id="dialogYesButton" class="button btn-orng" tabIndex="101" href="#">
            <span class="btn-inner">Yes</span>
        </a>
        <a id="dialogNoButton" class="button btn-orng" tabIndex="102" href="#">
            <span class="btn-inner">No</span>
        </a>
    </div>
</div>

Java code I am trying to execute: 我尝试执行的Java代码:

driver.findElement(By.xpath(//*[@id="save_quote_button"]/span)).click(); // After this the pop-up window gets displayed
driver.findElement(By.xpath(//*[@id="dialogYesButton"]/span)).click(); // Trying to click on the Yes button on the pop-up

It just skips the step without actually giving any error. 它只是跳过该步骤而没有实际给出任何错误。

As you are trying to click on the Yes button, this xpath may help you: 当您尝试单击“是”按钮时,此xpath可能会帮助您:

driver.findElement(By.xpath(//*[@id="dialoguebuttons"]/a[text()='Yes')).click();

Let me know if this helps you. 让我知道这是否对您有帮助。

If you are using firefox browser then install firebug Addon and firepath Addon and inspect that element using firepath and paste here that xpath between double quotes mentioned in below code: 如果您使用的是firefox浏览器,则安装firebug Addon和firepath Addon,并使用firepath检查该元素,并在此代码中粘贴以下代码中双引号之间的xpath:

driver.findElement(By.xpath(" ")).click();

If you are not familiar with firebug refer this link and try it. 如果您不熟悉firebug请参考链接并尝试。 It will help you out. 它将帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用硒单击 div 中弹出窗口的按钮 - Unable to click on button of a pop-up in div using selenium 单击导致弹出Java Selenium Webdriver的按钮 - Clicking on button that leads to pop-up Java Selenium Webdriver 如何使用Java处理Selenium WebDriver中的弹出窗口 - How to handle Pop-up in Selenium WebDriver using Java 使用 Selenium Webdriver 的登录弹出窗口 - Login Pop-Up Using Selenium Webdriver 无法单击 selenium webdriver 中的“按钮”(使用 Java) - Unable to click the 'button' in selenium webdriver (using Java) 如何使用WebDriver(Selenium JAVA)处理Telerik弹出窗口 - How to deal with Telerik pop-up window with WebDriver (selenium JAVA) 如何使用JAVA在Selenium Webdriver的Internet Explorer中处理服务器身份验证弹出窗口? - How can i handle Server authentication pop-up in Internet Explorer in Selenium Webdriver using JAVA? 如何使用带有Java的Selenium Webdriver处理允许弹出的Firefox插件 - How do I handle allow pop-up of plug-in for firefox using Selenium Webdriver with Java 无法使用Java切换到弹出窗口并在Webdriver中找到弹出窗口中的任何元素 - Not able to switch to pop-up window and find any elements in pop-up in Webdriver using Java 无法使用 selenium webdriver 和 java 单击 iframe 中的按钮 - Unable to click on a button present in iframe using selenium webdriver and java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM