0

Here are two HTML code examples from two different cases: Both the examples have common partial class names: "fa fa-circle atp-", only the end is different "-green" or "red".

I'm trying to locate class by partial name and return its full name, however I failed to do it.

1st code example:

<i ng-hide="atpCtrl.atp.isLoading &amp;&amp; !hasOverrideToken" class="fa fa-circle atp-green" ng-class="cssClass" ng-if="(showAtp &amp;&amp; !requireClick) || hasOverrideToken" uib-tooltip="Available in PL51 - Pilkington AGR Sochaczew" tooltip-append-to-body="true" tooltip-placement="top" tooltip-trigger="'mouseenter outsideClick'"></i>

2nd code example:

<i ng-hide="atpCtrl.atp.isLoading &amp;&amp; !hasOverrideToken" class="fa fa-circle atp-red" ng-class="cssClass" ng-if="(showAtp &amp;&amp; !requireClick) || hasOverrideToken" uib-tooltip="Not Available" tooltip-append-to-body="true" tooltip-placement="top" tooltip-trigger="'mouseenter outsideClick'"></i>

I tried the following:

#Locate the class
availability = driver.find_element(By.CSS_SELECTOR("fa fa-circle atp-"))

#Get full class name
full_class_name = availability.get_attribute("class")
Guy
  • 46,488
  • 10
  • 44
  • 88
PlayerXxXx
  • 25
  • 3
  • you can find the solution here, https://stackoverflow.com/questions/27049514/selenium-webdriver-finding-element-by-partial-class-name/56844649#56844649 – Ajeet Verma Mar 27 '23 at 06:31

1 Answers1

1

To find a class using CSS_SELECTOR you need to use . or class= to mention this is a class. You also need to mention this is a partial class name using contains *=

By.CSS_SELECTOR('.fa.fa-circle[class*="atp-"]')
Guy
  • 46,488
  • 10
  • 44
  • 88