XPath:: Get following Sibling
You should be looking for the second tr that has the td that equals ' Color Digest ', then you need to look at either the following sibling of the first td in the tr, or the second td.
Try the following:
//tr[td='Color Digest'][2]/td/following-sibling::td[1]
or
//tr[td='Color Digest'][2]/td[2]
http://www.xpathtester.com/saved/76bb0bca-1896-43b7-8312-54f924a98a89
XPath: Get following-sibling based on text() only
You almost got it right, here you go, you just needed to show where exactly you want to look for. I hope this helps:
//td[text()="Looking for"]/following-sibling::td[text()="This!"]
How to select following sibling/XML tag using XPath
How would I accomplish the nextsibling
and is there an easier way of doing
this?
You may use:
tr/td[@class='name']/following-sibling::td
but I'd rather use directly:
tr[td[@class='name'] ='Brand']/td[@class='desc']
This assumes that:
The context node, against which the XPath expression is evaluated is the parent of all
tr
elements -- not shown in your question.Each
tr
element has only onetd
withclass
attribute valued'name'
and only onetd
withclass
attribute valued'desc'
.
XPath to match only directly following siblings
Is there some reason you can't take the simple approach of picking all of the div
s that don't have id attributes?
div[not(@id)]
Or, perhaps, div
s with a style attribute?
div[@style]
If, for some reason, that's not acceptable, you can go with something more like what you were thinking:
div[@style][following-sibling::div[@id='foo1']]
Which gets all of the div
s with style attributes which come before div
s matching a particular id. Is that what you're asking for?
I imagine your actual input HTML is less trivial than the example you've provided, but all of these XPath expressions I've listed work with your example. If you could provide more specific detail about what your expected output is and what issues you've been facing then I can give you more help.
XPath - All following siblings except first specific elements
Use:
/table[@id='target']/following-sibling::*[not(self::table) and not(self::ol)]
|
/table[@id='target']/following-sibling::table[position() > 1]
|
/table[@id='target']/following-sibling::ol[position() > 1]
This selects all the following siblings of the table that are not table
and are not ol
and all the following table
siblings with position 2 or greater and all the following ol
siblings with position 2 or greater.
Which is exactly what you want: all following siblings with the exception of the first table
following sibling and the first ol
following siblings.
This is pure XPath 1.0 and not using any XSLT functions.
xpath with following-sibling
You can try following
instead of following-sibling
as mentioned h3
and table
nodes are not siblings:
//div[@id="topTenSellers"]//h3[@class="box-title" and .="OODR Items for next 20 Days"]/following::table[@class="table table-hover"]
Related Topics
How to Set an HTML Class Attribute in Markdown
How to Put a Bootstrap Glyphicon Inside an Asp:Button in Asp.Net
Square Div Where Height Is Equal to Viewport
When to Use <Span> Instead <P>
Filter Extensions in HTML Form Upload
Make Index.HTML Default, But Allow Index.PHP to Be Visited If Typed In
How to Navigate to a Section of a Page
How to Use Custom Fonts on a Website
Add External CSS File to Blogger Template
Display Adobe PDF Inside a Div
Thymeleaf - How to Add Checked Attribute to Input Conditionally
Streaming a Video from Google Drive Using HTML5 Video Tag
Why Is "&Reg" Being Rendered as "®" Without The Bounding Semicolon
How to Hide Text Field in HTML File Upload
Why Are Bootstrap's Form Elements Rendered Terribly with Struts2-Boostrap-Plugin