Skip to content
Advertisement

Is it possible to locate element by partial class match in Selenium

I’m getting starting with Selenium and I’m trying to locate the Next button on the cnn site and if it isn’t the last page to click on it, otherwise to end the program.

The html code for enabled button is:

<div class="pagination-arrow pagination-arrow-right cnnSearchPageLink text-active">
    "Next"
 <i class="icon icon--arrow-right"></i>
</div>

The html code for disabled button is:

<div class="pagination-arrow pagination-arrow-right text-deactive">
    "Next"
 <i class="icon icon--arrow-right"></i>
</div>

How should approach the solution? I tried is_enabled() or to find part of text in class name but didn’t succeed. What should I do?

Advertisement

Answer

You can use

div.text-active

CSS selector to represent the first HTML div that you have shared.

and

div.text-deactive

CSS selector to represent the second HTML div

Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the css selector and see, if your desired element is getting highlighted with 1/1 matching node.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement