royalblue
royalblue

Reputation: 449

Using CSS Selector to click a button

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.

Upvotes: 1

Views: 3943

Answers (1)

MartyIX
MartyIX

Reputation: 28648

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()

Upvotes: 1

Related Questions