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

Train Asked on September 9, 2014 in Selenium WebDriver.
Add Comment
  • 3 Answer(s)
    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

    Hi,

    You need to put the xpath in the place ┬ádriver.findElement(By.xpath(“your xpath”));

    Else webdriver will not be able to locate the webelement.

    If you are using properties file please check whether you have put in the xpath in the properties file.

    Thanks,
    Vishal S

    Doctor Answered on September 9, 2014.
    Add Comment

    Can you give the code for the above errot

    Doctor Answered on September 9, 2014.

    Please ask information using comments.

    on September 10, 2014.
    Add Comment
  • Your Answer

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