简体   繁体   中英

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. HTML code is :

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

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:

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:

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

If you are not familiar with firebug refer this link and try it. It will help you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM