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

Time:01-08

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 >
    "Next"
 <i ></i>
</div>

The html code for disabled button is:

<div >
    "Next"
 <i ></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?

CodePudding user response:

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.

  •  Tags:  
  • Related