jake wong jake wong - 5 months ago 42
Python Question

Selenium click on next button

How can i get selenium to click on the next button from the HTML code below?

<span class="action-btn" data-bind="visible: viewModel.page() < viewModel.pages(), click: viewModel.changePage(+1);">&gt;</span>

Initially I wrote:

elm = driver.find_element_by_class_name('action-btn')

But I noticed that in the website, there are other
with similar names as well. Such as
action-btn customize
action-btn right

With my current code, its basically just clicking on
action-btn customize
and my guess is because this button name comes before the code that I intended to click on.

How should I be writing my code instead?


Here is a screen shot of the frame. The yellow highlight is what I am trying to click on.

image of HTML code


Looking at your screenshot it seems the action-btn you want to click is the last one in pager class.

And, if you have only one div element with class pager, you could select all action-btn inside it and get the last one:

elem = driver.find_element_by_css_selector("div.pager span.action-btn:last-of-type");

Here are more details about :last-of-type selector:

The :last-of-type CSS pseudo-class represents the last sibling with the given element name in the list of children of its parent element.