Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97792

Unable to click on button of a pop-up in div using selenium

$
0
0

I'm trying to click on a button inside pop-up. However, webdriver always throws No such element exception. The pop-up is not an alert but a regular element defined inside a . It consists of a message and an OK button. I'm able to verify / locate the message element but unable to click on the button. Following is the html code for it.

<div id="yui_patched_v3_11_0_6_1522928024187_16" class="yui3-widget modal yui3-widget-positioned yui3-widget-stacked yui3-widget-modal yui3-resize" style="width: 95%; left: 334px; top: 167px; z-index: 0;" tabindex="0">
    <div id="yui_patched_v3_11_0_6_1522928024187_18" class="modal-content yui3-widget-stdmod">
        <div class="yui3-widget-hd modal-header">
            <div id="yui_patched_v3_11_0_6_1522928024187_112" class="toolbar-content yui3-widget component toolbar">
                <button type="button" class="btn close">×</button>
            </div>
            <h3>Message</h3></div>
        <div class="yui3-widget-bd modal-body">
            <div class="info-block">
                <table width="100%" cellpadding="0" cellspacing="0">
                    <tbody>
                        <tr>
                            <td width="127">
                                <div id="info_image_errorPriceConditioNotSelect" class="info-image restriction-image"></div>
                            </td>
                            <td>
                                <div id="info_content_errorPriceConditioNotSelect" class="info-content">None selected</div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="yui3-widget-ft modal-footer">
            <div id="yui_patched_v3_11_0_6_1522928024187_153" class="toolbar-content yui3-widget component toolbar">
                <button type="button" class="btn yui3-widget btn-content btn-focused" id="yui_patched_v3_11_0_6_1522928024187_500">OK</button>
            </div>
        </div>
    </div>
    <div class="yui3-resize-handles-wrapper">
        <div class="yui3-resize-handle yui3-resize-handle-br">
            <div class="yui3-resize-handle-inner yui3-resize-handle-inner-br">&nbsp;</div>
        </div>
    </div>
</div>

Below is my code through which I'm trying to access the button:-

driver.switchTo().activeElement();
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[starts-with(@id, 'yui_patched_v3_11_')]//div[@id="info_content_errorPriceConditioNotSelect"]"))));
    assertTrue(driver.findElement(By.xpath("//div[starts-with(@id, 'yui_patched_v3_11_')]//div[@id="info_content_errorPriceConditioNotSelect"]")).isDisplayed());
    Thread.sleep(5000);

    driver.findElement(By.xpath("//button[starts-with(@id,"yui_patched_v3_")][text()='OK']")).click(); //Webdriver throws exception here

I'm using selenium 3.9.1 and executing the scripts on chrome.
Any help would be appreciated.

Thanks,
Anuja


Viewing all articles
Browse latest Browse all 97792

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>