I need to click on the last button (CurrentPageUp) in a row. xPath does not work since nr of buttons change frequently. I tried


This does work but nr of buttons change frequently, so I cannot use it

Tried to loop to last button and execute it, but failed as well. Tried to select name but is is an arrow '>' and not sure how to use the '>' equivalent in the code to find and click on it.

.... First range of button codes

    <button onclick="CurrentPageUp();" 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">
  • 1
    If you always want the last button, why doesn´t getting all buttons via find_elements_by_tag_name("button") and just clicking the last element in the list work?
    – Daniel
    Jul 19, 2016 at 15:34
  • XPath should be your LEAST preferred method to locate any element. But for some reason is is FIRST for most people who are asking questions because they have problems locating elements. Go figure. Jul 19, 2016 at 15:47
  • Try to find elements by CSS or even XPATH if you needed, and them input in match code. But as always, any of them have positive and negative.
    – G.Guy
    Feb 11, 2018 at 9:09

2 Answers 2


To find the last button using Xpath try this:


So instead of giving a number, you can select the last one.


Have you tried selectors for css or xpath like:



//button[contains(@onclick, 'CurrentPageUp')]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.