0
class = "col-scope serialize"

I have an element in HTML with class name like above. When I try to get the class name with getAttribute("class") I am only getting the value col-scope.

How can I get the complete value col-scope serialize?

  • Are you sure your `class` attribute has not changed between you observed its value visually and tested it with Selenium? – Alexey R. Aug 12 '22 at 16:50

1 Answers1

0

As @JaSON mentioned in their comments:

Waiting for element with exact @class to extract that exact @class doesn't really make much sense


Solution

Ideally, to extract the value of the class attribute you need to use the other attributes (other than class attribute) to locate the element first and then you can use getAttribute("class") and you can use either of the following locator strategies:

  • Using cssSelector:

    System.out.println(driver.findElement(By.cssSelector("tagName[attributeName='attributeValue']")).getAttribute("class"));
    
  • Using xpath:

    System.out.println(driver.findElement(By.xpath("//tagName[@attributeName='attributeValue']")).getAttribute("class"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352