Home > Software design >  Selenium/Java Is returning error No such Element: Unable to locate the element
Selenium/Java Is returning error No such Element: Unable to locate the element

Time:05-21

I am trying to click "New Vehicle Search" on the page, but it seems to me I have the wrong web element locator (XPath or CSS) for this. I tried all possible options (CSS, XPath..) without success and I got an error:

Blockquote

[ERROR] NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[5]/div/div[4]/div1/div[2]"} (Session info: chrome=101.0.4951.67)

Blockquote

[New Vehicle Search button-Unable to locate the element] 1

sleep(10000);

driver.findElement(By.xpath("/html/body/div[5]/div/div[4]/div1/div[2]")).click();

Blockquote

CodePudding user response:

Use browser inspector and copy that xpath into element search. If it doesn't find anything, your xpath doesn't work.

You may need to check if the elements are located inside an iframe, which requires you to switch to that frame first.

CodePudding user response:

The class of the element seems to be unique on that webpage, maybe you can try locating it by class?

driver.findElement(By.className("store-ymm-newvehsearch"))
  • Related