Dont you mind
Dont you mind

Reputation: 43

Can not find button. Selenium java

I have this code:

HTML 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

Answers (1)

Prophet
Prophet

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

Related Questions