1

I am trying to click a button using Selenium.

Below is the code

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

I tried to do this by the css selector:

clickbutton=driver.find_element_by_css_selector("button.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only")

**My error: Unable to locate element: { method: "css selector","selector":"button.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only"} **

Am I approaching this wrong? Im not understanding the error. Shoud I use another Locator?

7
  • do you really need to target all those classes? what if you do ui-dialog-buttonset button.ui-button Commented Nov 17, 2015 at 22:03
  • still doesn't work when I tried those Commented Nov 17, 2015 at 22:15
  • is there more than one of those buttons? or have you tried using find_element_by_class_name? Commented Nov 17, 2015 at 22:19
  • Theres 2 buttons a "create" button (the button I am trying to click) and a close button. I have tried driver.find_element_by_class_name ("ui-dialog_buttonset") Commented Nov 17, 2015 at 22:23
  • i see. do you know xpath? Commented Nov 17, 2015 at 22:30

1 Answer 1

3

Your css selector is ok the problem is related to html code which setting aria-disabled="false" for compability. For Web3 documentation it means that related element and descandent are active but in your case it is not working.

Simple you can set the aria-disabled="true" then you can interact with the button but even you set it back to false it still works. To change the button attribute, you can use execute_script. Alternative to your css you use this css too: .ui-dialog-buttonset > button

>>> dr.find_element_by_css_selector(".ui-dialog-buttonset > button").get_attribute("aria-disabled")
u'false'
>>> dr.execute_script('document.querySelector(".ui-dialog-buttonset > button").setAttribute("aria-disabled", true)')
>>> dr.find_element_by_css_selector(".ui-dialog-buttonset > button").get_attribute("aria-disabled")
u'true'
>>> dr.find_element_by_css_selector(".ui-dialog-buttonset > button").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.