1

I currently trying to test a dialog with Selenium WebDriver but the "Create Employee" button doesn't have an id nor a name. This is what the code looks like.

<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
    <div class="ui-dialog-buttonset">

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Create Employee</span>
         </button>

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Cancel</span>
         </button>

    </div>

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Create Employee</span>
         </button>

         <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
              <span class="ui-button-text">Cancel</span>
         </button>

</div>

Can anyone provide me with the java code that will click the button in the dialog box? Thanks

1
  • Hey from above html page i guessing there are two buttons with same name as 'Create Employee' am i right? Commented May 14, 2013 at 7:22

4 Answers 4

4

Try Below code.

 driver.findelement(By.xpath("//button[@type='button']/span[text()='Create Employee']")).click();
Sign up to request clarification or add additional context in comments.

Comments

1

As an alternative to the xpath stuff, which I found troublesome for newbies, I found that jQueryUI dialog can add IDs to the results.

Instead of:

$("#stuff").dialog({
    buttons: {
            "Yes": function() {

write:

$("#stuff").dialog({
    buttons: {
            "Yes": { text: "Yes",
                     id: "#mystuff-yes",
                     click: function() {

Comments

0

If you don't have any way to select any element I would suggest the use of xpath I would suggest installing some addons or extensions on your browser for getting the xpath of the element you want to interact. Then Use that xpath for your purpose.

Comments

-1

If your text does not change, you can use:

$('.ui-button-text').click(function() {
    if($(this).text() == 'Create Employee') {
        // Your code here
    }
});

Demo

1 Comment

I already have the code. I just need to test it using Selenium WebDriver to submit a form.

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.