2

Am using the selenium web driver for internet explorer (IEDriverServer_x64_2.44.0)

I am trying to click on a button which is on a jquery dialog MY Code is as follows:

$("#dialog-text").html(dlg_message);
        $("#dialog-msg").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 'auto',
            modal: true,
            draggable: false,
            title: dlg_title,
            buttons: btns,
            close: function () {
                //$('body').css('overflow', 'visible');
                for (var item in controlsToEnable)
                    getControl(controlsToEnable[item]).disabled = false;
            },
            open: function (event, ui) { $('.ui-widget-overlay').css('width', '100%'); }
        });

        $("#dialog-message").dialog('open');
        $(this).parents('.ui-dialog-buttonpane button:eq(' + indexButtonFocused + ')').focus();


<div id="dialog-msg" style="display: none;">
    <p style="margin: 0 7px 50px 7px;">
        <span class="ui-icon ui-icon-circle-check"></span><span id="dialog-text">MESSAGE</span>
    </p>
</div>

This pop up comes with 2 buttons Yes and No (i store this in the var: btns)btns['No'] and btns['Yes'] How do I click on this button? I have tried,

driver.SwitchTo().Frame(0);
        driver.FindElement(By.Name("No")).Click();

also tried,

driver.SwitchTo().Alert().Accept(); --> this works for confirm message

So basically I am trying to click on the buttons of this dialog box and am not able to.

5
  • Can someone please help me out here Commented Nov 18, 2014 at 9:51
  • can u please paste the HTML being generated Commented Nov 18, 2014 at 10:31
  • '<DIV class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" sizcache="0" sizset="1"><DIV class=ui-dialog-buttonset sizcache="0" sizset="1"><BUTTON aria-disabled=false class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role=button jQuery1416309408478="17"><SPAN class=ui-button-text>No</SPAN></BUTTON><BUTTON aria-disabled=false class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role=button jQuery1416309408478="19"><SPAN class=ui-button-text>Si</SPAN></BUTTON></DIV></DIV>' Commented Nov 18, 2014 at 11:25
  • tats the html code that was generated, it has a ui button pane, plus buttons in it, as it can be seen in the previous code i pasted, the dialog has lot of other features for which i have not pasted the html code. the code i have pasted is for the button pane and the buttons. Commented Nov 18, 2014 at 11:27
  • @Anuragh27crony, Please check the code I have pasted and let me know if something more is required Commented Nov 18, 2014 at 11:28

1 Answer 1

1

Given the code you've pasted in your question and the HTML of the button you supplied in the comment (you should edit the question and put the button HTML in the question), your WebDriver code will not find the button. The button element does not have a name attribute, so it cannot be found using the By.Name() locator strategy.

Realize that attempting to find the element by its text is generally not a great approach. Having said that, you could try something like the following:

// WARNING!! Untested code below. May not be exactly correct.
driver.FindElement(By.XPath("//div[contains(., 'No')]"));
Sign up to request clarification or add additional context in comments.

3 Comments

I dont have a button in html, this button is basically a jquery dialog button, not a html button, any suggestions on how to click a jquery dialog button?
Have you tried the suggestion in my answer? Even if you're using jQueryUI, the elements written to the page eventually get rendered somewhere as HTML. This is very clear in your comment to the original issue where you post the generated HTML. Unless the "dialog" you're manipulating is created by a plain JavaScript alert(), confirm(), or prompt(), you'll use the standard findElement() and click() methods, assuming the driver's "focus" is on the same frame as the element you're attempting to find.
yeah, it finally got rendered as html. so it worked. thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.