Xpath cannot select an element

68 views
Skip to first unread message

robocop

unread,
Mar 30, 2012, 12:23:39 PM3/30/12
to seleniu...@googlegroups.com
Hi,
 
I am trying to select an element <font face="MS Sans Serif,Arial,Helvetica" color="blue" size="1">&nbsp;&nbsp;Ireland&nbsp;&nbsp;</font>

below is the html snippet and the xpath code
 
<td valign="bottom" nowrap="">
<img border="0" width="38" hspace="0" height="24" align="LEFT" alt="" src="images/cwt_rd.gif">
<table cols="1" cellspacing="0" border="0" height="3" cellpading="0" rows="1">
<a onclick="Exp(1); return false;" href="#">
<a onclick="GetEmp(1,true); return false;" href="#">
<table class="deptsel" cols="1" cellspacing="0" cellpadding="0" border="0" bgcolor="#0D9B9B" width="1" height="21" rows="1">
<tbody>
<tr>
<td nowrap="">
<a name="node1"></a>
<a class="PLAIN" onclick="Sel(1); return false;" href="#">
<font face="MS Sans Serif,Arial,Helvetica" color="white" size="1">&nbsp;&nbsp;Ireland&nbsp;&nbsp;</font>
 

xpath=//a[@name="node1"]//font
 
However I can get a far as xpath=//a[@name="node1"] but not to the font face tag. Can you help?
 
thanks

Mike Riley

unread,
Mar 30, 2012, 3:07:25 PM3/30/12
to Selenium Users
If you have a name property use it directly instead of XPath. It is
both faster (in execution speed) and easier (to enter) to say
"name=node1".

For selecting the font tag I am not sure how well that will work, but
you only want to use // at the start, not in the middle (AFAIK).

So try this: //a[@name="node1"]/font

Mike

Jayaraman - Inspired to become Software Architect

unread,
Mar 31, 2012, 1:56:59 AM3/31/12
to seleniu...@googlegroups.com
Could you plz try with this xpath //a[@class='PLAIN']/font.

-Jay!!

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/W1LwA6-LHOIJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

robocop

unread,
Apr 2, 2012, 12:34:10 PM4/2/12
to seleniu...@googlegroups.com
thanks guys

below worked but another snag works in FIREFOX but not IE 9.0
The line that fails is the assert for some reason-see code below



    @Test //select group
    public void testFileMnu() throws Exception {
        //testLogIn();
        selenium.click("css=ul.jd_menu> li");
        selenium.click("link=Select Group");
        selenium.waitForPageToLoad("90000");
        selenium.click("xpath=//a[@class='PLAIN']//font[contains(.,'Applegreen')]");
        Thread.sleep(6000);
        assertTrue(selenium.isElementPresent("xpath=//a[@class='PLAIN']//font[contains(.,'Applegreen') and @color='white']")); //selected
        //assertTrue(selenium.isElementPresent("xpath=//a[@class='PLAIN']//font[contains(.,'Applegreen')]")); //selected
        //xpath=//a[@class='PLAIN']//font[contains(.,'Applegreen') and @color='white']
        selenium.click("name=TB0");
        selenium.waitForPageToLoad("90000");
-Jay!!

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Hien Ngo

unread,
Apr 2, 2012, 3:15:19 PM4/2/12
to seleniu...@googlegroups.com
Yes, your code looks correct. If that element is present the statement will return true, and throw an exception.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Mark Collin

unread,
Apr 2, 2012, 4:15:00 PM4/2/12
to seleniu...@googlegroups.com

Is the DOM rendered in the same way in IE and FF?

-Jay!!

--

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

robocop

unread,
Apr 3, 2012, 4:09:50 AM4/3/12
to seleniu...@googlegroups.com
Hi,

I do not understand this to be honest. If the element is present it return the correct value of true, so why does it throw an exceptions?

thanks

robocop

unread,
Apr 3, 2012, 12:30:33 PM4/3/12
to seleniu...@googlegroups.com
Hi,

I am a newbie so would not know how to begin to answer that questions? Any pointers.
Is there any way to check that the xpath expression in IE like you can do in firefox using firefinder etc so maybe I could tweak it for IE?

thanks

-Jay!!

--

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Mark Collin

unread,
Apr 4, 2012, 1:28:33 AM4/4/12
to seleniu...@googlegroups.com

Generally you need to learn about the DOM and XPath properly:

 

·         http://www.w3.org/DOM/

·         http://www.w3.org/TR/xpath-functions/

 

There are probably tools for IE that take XPath’s and see if they are valid, Google for them (I don’t use them personally so don’t know of any good ones).  The IE Dev toolbar should enable you to work out some absolute XPath’s which is good as a starter.

 

Unfortunatly the best way to understand XPath and the DOM is to read and understand the specs above (That’s how I did it).

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of robocop
Sent: 03 April 2012 17:31
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Xpath cannot select an element

 

Hi,



I am a newbie so would not know how to begin to answer that questions? Any pointers.
Is there any way to check that the xpath expression in IE like you can do in firefox using firefinder etc so maybe I could tweak it for IE?

thanks

On Monday, April 2, 2012 9:15:00 PM UTC+1, Mark Collin wrote:

Is the DOM rendered in the same way in IE and FF?

 

-Jay!!

--

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/-gJtHxM6IOwJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

robocop

unread,
Apr 4, 2012, 4:23:33 AM4/4/12
to seleniu...@googlegroups.com
Thanks
 
I am familar with both but not sure how I would go about answering your questions?

-Jay!!

--

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/-gJtHxM6IOwJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Hien Ngo

unread,
Apr 4, 2012, 5:16:47 PM4/4/12
to seleniu...@googlegroups.com
I have a question about the Thread.Sleep(6000); why do you need that 6 secs sleep, and what happens at that point?

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/_62-Um368JwJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

robocop

unread,
Apr 5, 2012, 3:53:35 AM4/5/12
to seleniu...@googlegroups.com
Hi,
 
just to give the page some time to load, why?
 
thanks

Mark Collin

unread,
Apr 5, 2012, 7:49:06 AM4/5/12
to seleniu...@googlegroups.com

Then use:

 

selenium.waitForPageToLoad("6000");

 

Never use Thread.sleep it’s putting a hard coded 6 second wait in your test for no reason and is pointless/unhelpful and the wrong way to do things.

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of robocop
Sent: 05 April 2012 08:54
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Xpath cannot select an element

 

Hi,

 

just to give the page some time to load, why?

-Jay!!

--

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/-gJtHxM6IOwJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/_62-Um368JwJ.


To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/QkkYUv1b7zUJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Hien Ngo

unread,
Apr 5, 2012, 10:18:47 AM4/5/12
to seleniu...@googlegroups.com
The 6 sec sleep makes your test fail intermittently
for the page loading time may be longer on some days when the network/hardware are slower, or underload.

robocop

unread,
Apr 5, 2012, 10:31:18 AM4/5/12
to seleniu...@googlegroups.com
Hi Mark/Lerry


I agree it is pointless alright. I will give this a go and see how I get on. Have a good Easter and thanks for your help on this. No doubt I will be asking more questions :-)

thanks

-Jay!!

--

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rsLf9t-BoTgJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/-gJtHxM6IOwJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/_62-Um368JwJ.


To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/QkkYUv1b7zUJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages