RE: Cannot find elements when the XPath expression is null.

Answered

Hi All;
I’m getting this error.Can anyone please explain me about this?
java.lang.IllegalArgumentException: Cannot find elements when the XPath expression is null.

Thanks

Priya Train Asked on September 9, 2014 in Selenium WebDriver.
Add Comment
3 Answers
Best answer

Hi;
When I use this,
driver.findElement(By.id(“lnkSort”)).click();
It works fine for me.
But if I use the xpath,
driver.findElement(By.xpath(“//a[@id=’lnkSort’]”)).click();
It doesn’t and gives this error:
java.lang.IllegalArgumentException: Cannot find elements when the XPath expression is null

I can’t understand why i’m getting this error because I have used┬ádriver.findElement By.xpath so many times in my scripts and now I’m getting this error.

Train Answered on September 10, 2014.

Not sure what is the issue, as if xpath is wrong, then it should have said that not able to find the xpath. Try providing us the website or complete code of your test. Still try with full xpath starting from html.

on September 10, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.