I need to click on the last button (CurrentPageUp) in a row. xPath does not work since nr of buttons change frequently. I tried
find_element_by_xpath('//*[@id="ShowProducts_PagesTop"]/span/button[11]/span')
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">
>
</span></button>
</span></div>
-
1If 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– Daniel2016年07月19日 15:34:42 +00:00Commented 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.Peter M. - stands for Monica– Peter M. - stands for Monica2016年07月19日 15:47:15 +00:00Commented 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– G.Guy2018年02月11日 09:09:44 +00:00Commented Feb 11, 2018 at 9:09
2 Answers 2
To find the last button using Xpath try this:
find_element_by_xpath('//*[@id="ShowProducts_PagesTop"]/span/button[last()]/span')
So instead of giving a number, you can select the last one.
Have you tried selectors for css or xpath like:
button[onclick*='CurrentPageUp']
or
//button[contains(@onclick, 'CurrentPageUp')]