Reputation: 43
I have this code:
Then using selenium I write this:
driver.findElement(By.className("extra-delivery-item")).click();
The question is why does selenium tell me: no such element: Unable to locate element: {"method":"css selector","selector":".extra-delivery-item"
P.S. I have already located some buttons and successfully clicked on them, everything works, except that button.
Upvotes: 1
Views: 199
Reputation: 33361
This element is actually has multiple class names. So to select it according to single class name you can use XPath or CSS selector.
Like this:
driver.findElement(By.xpath("//div[contains(@class,'extra-delivery-item')]")).click();
or
driver.findElement(By.cssSelector("div.extra-delivery-item")).click();
Selecting element by class name, like you tried to use
findElement(By.className("extra-delivery-item"))
means matching element with class attribute exactly matching that value, extra-delivery-item
in this case. While the element class attribute here is extra-delivery-item extra-delivery-item-selected
Upvotes: 1