How to identify element via its neighbor

44 views
Skip to first unread message

Linh Vu

unread,
May 19, 2011, 1:07:55 AM5/19/11
to Selenium Users
Hi all

I have htlm code below:

<td>
<div id='you'> you </div>
<div> LOVE </div>
</td>

<td>
<div id='me'> me </div>
<div> LOVE </div>
</td>

I have element 2 element the same and it have text is LOVE.

How to identify element via its neighbor?

I mean how to find a element have text is LOVE of you or LOVE of me?
and of couse, it must to base on element neighbor.

winfred zhu

unread,
May 19, 2011, 1:47:53 AM5/19/11
to seleniu...@googlegroups.com
you can use  preceding-sibling and  following-sibling to identify the element you want.



2011/5/19 Linh Vu <vuth...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
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.


Linh Vu

unread,
May 19, 2011, 1:59:34 AM5/19/11
to seleniu...@googlegroups.com
Thank winfred zhu.
Can you give me a example with my html code?
--
Mr. VuThe Linh
eXo Platform SEA
8 Flr, Thaiha building, 18/11 alley, Thaiha Str, Hanoi
Skype: vu.the.linh
website:www.exoplatform.com

http://groups.google.com/group/ChonMotNiemVui : vì một ngày mai tương sáng

Phone : +84 984 303 104

Jayakumar C

unread,
May 19, 2011, 2:02:43 AM5/19/11
to seleniu...@googlegroups.com
@ Linh Vu,

Hope this is what you are looking for,

css=#you ~ div
css=#me ~ div

or

//*[@id='you']/following::div
//*[@id='me']/following::div

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
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.




--
Jayakumar

Linh Vu

unread,
May 19, 2011, 2:18:49 AM5/19/11
to seleniu...@googlegroups.com
Beautyful! I love you.

Thanks :-p

Sasi kumar

unread,
May 19, 2011, 2:50:06 AM5/19/11
to Selenium Users
i have below html ,so i used
//div[@id="79620000002701012img2"]/following::span but is shows all
the span following div (200 matches),but when i try //
div[@id="79620000002701012img2"] it shows only one value in
firebug! ,please help me



<div id="79620000002701012img2" class="ltFc"/>
<span id="79620000002701012sp"
onclick="setFolderId("79620000002701012")"
ondblclick="renmFol(event,"79620000002701012",fIn["79620000002701012"]
["fld"])">Temp</span>

On May 19, 11:18 am, Linh Vu <vuthel...@gmail.com> wrote:
> Beautyful! I love you.
>
> Thanks :-p
>
> On Thu, May 19, 2011 at 1:02 PM, Jayakumar C <jayakumaree...@gmail.com>wrote:
>
>
>
>
>
>
>
>
>
> > @ Linh Vu,
>
> > Hope this is what you are looking for,
>
> > css=#you ~ div
> > css=#me ~ div
>
> > or
>
> > //*[@id='you']/following::div
> > //*[@id='me']/following::div
>

Mark Collin

unread,
May 19, 2011, 3:36:30 AM5/19/11
to seleniu...@googlegroups.com

//div[.=’ LOVE ‘][preceding-sibling::div[.=’me’]]

 

Or

 

//div[.=’you’]/following-sibling::div[.=’ LOVE ‘]


-- This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error please notify postm...@ardescosolutions.com

Mark Collin

unread,
May 19, 2011, 3:38:04 AM5/19/11
to seleniu...@googlegroups.com
What are you trying to do? Just get the span after the div? It has an ID so why not just key into that?


--

Sasi kumar

unread,
May 19, 2011, 4:35:22 AM5/19/11
to Selenium Users
just for example iam asking how to proceed with that.that is if i want
to click that span without id!
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

Mark Collin

unread,
May 19, 2011, 5:12:04 AM5/19/11
to seleniu...@googlegroups.com
Try:

//div[@id="79620000002701012img2"]/following-sibling::span[1]

--


This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

sam6

unread,
May 19, 2011, 5:24:20 AM5/19/11
to Selenium Users
this is really helpful
> If you have received this email in error please notify postmas...@ardescosolutions.com

Sasi kumar

unread,
May 19, 2011, 9:30:20 AM5/19/11
to Selenium Users
thanks it worked . one more clarification, from below is it possible
to get the td ,<td class="label" width="25%">Email:</td> using input
id="property"?


<tr id="Information">
<td class="label" width="25%">Title:</td>
<td class="element" width="25%">
<td class="label" width="25%">Email:</td>
<td class="element" width="25%">
<input id="uiType_prop" type="hidden" value="25" name="uiType_prop"/>
<input id="property" class="textField" type="text" maxlength="100"
style="width:100%" name="property"/>
</td>
</tr>

Mark Collin

unread,
May 19, 2011, 9:44:01 AM5/19/11
to seleniu...@googlegroups.com
//input[@id='property']/../../td[.=' Email:']

Or

//input[@id='property']/../preceeding-sibling::td[.=' Email:']

Or

//input[@id='property']/../preceeding-sibling::td[1]

Or

//input[@id='property']/ ancestor::tr/td[.=' Email:']

And probably a few other ways as well

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

--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Sasi kumar

unread,
May 20, 2011, 1:38:48 AM5/20/11
to Selenium Users
it says invalid xpath for first 3 and not macthing node for last one?
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

Lutfi Dughman

unread,
May 20, 2011, 2:29:50 AM5/20/11
to seleniu...@googlegroups.com
this is the same as Marks but bit changed


//input[@id='property']/../..//td[contains(.,'Email')]

i added the last //td

and the contains.

give it a try

Sasi kumar

unread,
May 20, 2011, 2:35:35 AM5/20/11
to Selenium Users
yes it works ,thanks.what was the problem in marks xpath ?

Mark Collin

unread,
May 20, 2011, 3:45:21 AM5/20/11
to seleniu...@googlegroups.com
There is an extra space in my last XPath (type). There is nothing wrong
with my XPaths, you probably have whitespace that I haven't picked up. The
contains is not performing an exact match it is performing a substring
match. The XPaths I provded are assuming an exact text match so if the
value specified in .='<value>' is not exact it will not match.

--


This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Sasi kumar

unread,
May 20, 2011, 9:29:24 AM5/20/11
to Selenium Users
oh ok thanks a lot.
> If you have received this email in error please notify postmas...@ardescosolutions.com

Lutfi Dughman

unread,
May 20, 2011, 10:50:03 AM5/20/11
to seleniu...@googlegroups.com
another important difference in th expaths is the use of the //td insted of /td.



Reply all
Reply to author
Forward
0 new messages