Vamsi
Vamsi

Reputation: 78

Unable to click on a button using watir-webdriver

Here is my html:

<p class="actions">
  <input style="float: right" id="submit" type="submit" name="Create account" value="Update profile">
  <button name="cancel" style="padding: 10px 10px" onclick="window.close(); return false">Cancel</button>
  <button name="delete" style="padding: 10px 10px" onclick="window.location.href = 'https://88888.dev2.ext-dev.mysite.com/plugins/social/profile/delete?sessionKey=521f6a65e4b01c799ac48260&amp;webSocketIdentifier=521f6a65e4b01c799ac4825f'; return false">Delete account</button>
</p>

I have used:

[email protected](:css => "p.actions > delete").click

Upvotes: 0

Views: 808

Answers (2)

Justin Ko
Justin Ko

Reputation: 46826

Since you are using Watir, it is often better for readability to avoid css and xpath unless there is no other solution.

You should be able to do:

@browser.button(:name => 'delete').click

If the paragraph is an important part in differentiating the delete link, you may need to do:

@browser.p(:class => 'actions').button(:name => 'delete').click

If you really want to use css, I think it should have been:

@browser.element(:css => "p.actions > [name=delete]").click

or

@browser.element(:css => "p.actions > button[name=delete]").click

Note that "delete" is the value of the button's name attribute, not its class.

As per discussion in the comments, the element was also in a popup browser window. This has to be accessed using:

@browser.windows.last.use{ browser.button(:name => 'delete').click }

Upvotes: 2

Robbie Wareham
Robbie Wareham

Reputation: 3428

If your HTML does not contain the following html, then your CSS selector is wrong;

<p class='actions>
    <delete></delete>
</p>

Upvotes: 1

Related Questions