Cannot find element when the XPath expression is null.

2,067 views
Skip to first unread message

Jianah Javier

unread,
Jan 20, 2016, 3:08:35 AM1/20/16
to Selenium Users
Hi All

I was trying to double click on div element and an error appears "Cannot find element when the XPath expression is null." Hoping you can help me on this. When you mouseover the textarea there is a tooltip showing Double click to add/edit contents.

Please Note that the property file is working fine in other method. 

HTML:
<div id="description">
<div class="template">
<div class="dataRow lang english">
<div class="formCellLeft">
<div class="formCellRight">
<div class="inputText ui-corner-all editorDIV" title="Double click to add/edit contents."/>
</div>
</div>
</div>
</div>

xpath: .//*[@id='description']/div/div/div[2]/div 

Here is my code:

public static void dclickTxtarea(String object, String data){
try{
WebElement element = driver.findElement(By.xpath(OR.getProperty(object)));
Actions action = new Actions(driver).doubleClick(element);
action.build().perform();
}catch(Exception e){
Log.info("Unable to double click on Webelement " + object + "---" + e.getMessage());
}
}

Mark Collin

unread,
Jan 20, 2016, 4:12:25 AM1/20/16
to Selenium Users
Looks like:

OR.getProperty(object)

returns null.

What is the value of object, and what does OR.getProperty() do?

Jianah Javier

unread,
Jan 20, 2016, 4:26:07 AM1/20/16
to seleniu...@googlegroups.com
Hi Mark,

I am calling a property file and the property file(OR) has an object and value of xpath. See below simple code and still this will return with the same error:

WebElement element = driver.findElement(By.xpath(.//*[@id='description']/div/div/div[2]/div ));
Actions action = new Actions(driver).doubleClick(element);
action.build().perform();

The given selector  is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression  because of the following error:
SyntaxError: The expression is not a legal expression.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0471904c-b4a5-4588-9d17-547cebf4d996%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

PeterJeffreyGale

unread,
Jan 20, 2016, 4:45:53 AM1/20/16
to Selenium Users
Your XPath string is not wrapped in quotes.

Jianah Javier

unread,
Jan 20, 2016, 6:53:24 AM1/20/16
to seleniu...@googlegroups.com
Hi peter,

Same error appears
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Shailendra Bhadauria

unread,
Jan 20, 2016, 7:05:45 AM1/20/16
to seleniu...@googlegroups.com
Hi Jianah,

I have observed xpath that you mentioned in email, Can you please try after removing the intial dot (.) in Xpath.

Hope so it will work.

Shailendra 


For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Shailendra Singh Bhadauria
Email: shailendra...@gmail.com

Shailendra Bhadauria

unread,
Jan 20, 2016, 7:05:58 AM1/20/16
to seleniu...@googlegroups.com
Or please share me the URL of the app that you are automating

Jianah Javier

unread,
Jan 20, 2016, 10:18:01 PM1/20/16
to seleniu...@googlegroups.com
Hi Shailendra,

after removing the .(dot) in xpath below error appears.

The given selector //[@id='description']/div/div/div[2]/div is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression //[@id='description']/div/div/div[2]/div because of the following error:
SyntaxError: The expression is not a legal expression.

Uma D

unread,
Jan 20, 2016, 10:31:16 PM1/20/16
to Selenium Users
Hi,
 Try to use below Xpath in the code,

Xpath: //div[@id='description']/div/div/div[2]/div 

Shailendra Bhadauria

unread,
Jan 20, 2016, 10:39:08 PM1/20/16
to seleniu...@googlegroups.com
Hi Jianah,

I asked you to remove dot only. Ok let it be kindly use below:

//*[@id='description']/div/div/div[2]/div

Regards
Shailendra

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

murali seleniumtrainer

unread,
Jan 21, 2016, 3:22:05 AM1/21/16
to Selenium Users
Hi,

Why can't you try to create xpath with title here. some thing like this //div[@title='Double click to add/edit contents.']

please check if the above xpath returning required single or multiple elements.

Thank You,
Murali

Mark Collin

unread,
Jan 21, 2016, 3:50:23 AM1/21/16
to Selenium Users
As you can see the error has changed (previously it said that the xpath was null, now it says that the selector is invalid.

You don't have any quotes around the XPath (I would expect your development IDE to be sticking red lines under it highlighting the problem).

If you change it to:

WebElement element = driver.findElement(By.xpath("//*[@id='description']/div/div/div[2]/div"));
Actions action = new Actions(driver).doubleClick(element);
action.build().perform();

The code should now be valid.

That being said it's a pretty brittle XPath so you will probably have problems in the future if the structure of the page you are testing changes,
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

Jianah Javier

unread,
Jan 21, 2016, 4:10:31 AM1/21/16
to seleniu...@googlegroups.com
Hi Mark and Shailendra,

Yes you are right its now ok.  Thank you.

But can you explain why the .(dot) should be remove though using firebug it generate the xpath with a .(dot) ?

Cheers,
Jianah

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/06cd4bc5-6c4b-4c1a-b520-314ade30dd0e%40googlegroups.com.

Anand Somani

unread,
Jan 21, 2016, 4:31:23 AM1/21/16
to seleniu...@googlegroups.com
@Jianah,
Can you try with .(dot) in xpath ?
WebElement element = driver.findElement(By.xpath(".//*[@id='description']/div/div/div[2]/div"));

Actions action = new Actions(driver).doubleClick(element);
action.build().perform();

Thanks & Regards,
Anand Somani
Refer myBlogs: http://seleniumtestingguide.blogspot.in/


Anand Somani

unread,
Jan 21, 2016, 4:34:04 AM1/21/16
to seleniu...@googlegroups.com

Thanks & Regards,
Anand Somani
Refer myBlogs: http://seleniumtestingguide.blogspot.in/


Uma D

unread,
Jan 21, 2016, 12:32:56 PM1/21/16
to Selenium Users
Hi,

Try to use below xpath

xpath: //div[@id='description']/div/div/div[2]/div

Regards,
Uma


On Wednesday, January 20, 2016 at 3:08:35 AM UTC-5, Jianah Javier wrote:

Mark Collin

unread,
Jan 22, 2016, 3:47:30 AM1/22/16
to Selenium Users
. means use the current element.  You don't have a current element.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

Jianah Javier

unread,
Jan 25, 2016, 3:28:49 AM1/25/16
to seleniu...@googlegroups.com
Thank you Mark. 

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6197143f-c819-486b-8673-4ca9f63b61c2%40googlegroups.com.

nikhil rao

unread,
Sep 23, 2016, 3:16:36 AM9/23/16
to Selenium Users
Hi All,

Im unable to find webelemt on below URL:

http://demo.actitime.com

Go to Tasks Page--> Click on Create Tasks-> After this Im unable to select the Project.

Regards
Nikhil
Reply all
Reply to author
Forward
0 new messages