1

I want to click this button using css_selector.

<div class="ui-buttonset">
    <button class="ui-button ui-dfault ui-text-only" type=" button"
role="button" aria-disabled="false">
        <span class-"ui-button-text">Save</span>
    </button>
</div>

There are 2 buttons save and cancel. They both have the same code. How do I click the save button using css_selector?

I have tried driver.find_element_by_css_selector("button.ui-button").click()

But it doesn't work.

4
  • 1
    What about driver.find_element_by_css_selector("button.ui-button:first-child").click()? Or driver.find_element_by_css_selector("button.ui-button:last-child").click()? Commented Dec 21, 2015 at 15:39
  • Are the buttons next to each other? Would it not be easier to add an id attribute? Or perhaps a wrapper around each button with a more specific id or class? Commented Dec 21, 2015 at 15:50
  • @MartinVseticka Thank you your suggestion works Commented Dec 21, 2015 at 15:55
  • @royalblue Super, I posted it as an answer. Commented Dec 21, 2015 at 15:57

1 Answer 1

1

You can use one of the following selectors:

driver.find_element_by_css_selector("button.ui-button:first-child").click()
driver.find_element_by_css_selector("button.ui-button:last-child").click()
Sign up to request clarification or add additional context in comments.

Comments

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.