0

I am using "class name" attribute to locate element in Flip-kart like this:

WebElement element = driver.findElement(By.className("_1QZ6fC _3Lgyp8"));

The error I am getting is:

org.openqa.selenium.NoSuchElementException: Unable to locate element: ._1QZ6fC\ _3Lgyp8

HTML code of the element is as follows:

<span class="_1QZ6fC _3Lgyp8">Electronics<svg width="4.7" height="8" viewBox="0 0 16 27" xmlns="http://www.w3.org/2000/svg" class="_3ynUUz"><path d="M16 23.207L6.11 13.161 16 3.093 12.955 0 0 13.161l12.955 13.161z" fill="#fff" class="_3Der3h"></path></svg></span>

Target webelement and website - The "Electronics" category of the header in the URL https://www.flipkart.com/

1 Answers1

1

Running the above line produces the following error: org.openqa.selenium.InvalidSelectorException: Compound class names not permitted

Regarding this you can find more details from this earlier query Selenium Compound class names not permitted

Besides using the classname option in the specified page will result in the selection of multiple elements, as we can see there are atleast 7 items having the same classname.

Instead of this, you can use xpath to locate the element, something like the following:

driver.findElement(By.xpath("//span[contains(.,'Electronics')]"));

Krishna
  • 198
  • 6