Jump to content

XPath Attributes and how to use them


javaguy78
 Share

Recommended Posts

Ok, I have been working with xpath for a long time and need some help.I am using the xpath checker for Firefox to verify my xpath, so I have it working well. I do have a reference questions though, I am trying to find a specific input using

//input

and I can find them by name or by order, but I am interested in more information. Is there a way to verify the text that comes after the input? I saw somewhere online that this might work

//input[@beforeText='Text that comes after input']

But that's not working for me. Basically here is my question:is there a place online that lists out the available attributes xpath is aware of?

Link to comment
Share on other sites

No offense, but for someone that has worked "for a long time" with XPath, you're asking a question even an XPath newbie wouldn't ask. Or at least you're asking it the wrong way.XPath is used to navigate elements and attributes from an XML file. The elements and attributes XPath can read are determined by the actual XML file. The last XPath you're showing will make sence if your XML file contains something like:

<input beforeText="Text that comes after input">The result of the XPath expression</input>

You can check out other regions in predicates by simply putting the location of that other ndoe, relative to the current context of the XPath expression. For example, an XML file containing something like

<input>The result of the XPath expression</input>Text that comes after input

(which is what I think you're really trying to process)You can do so with something like

//input[string(following-sibling::text()[1])='Text that comes after input']

I think.

Link to comment
Share on other sites

Thanks.. that pointed me in the right direction for what I need to do. I actually needed to do

//input[contains(following-sibling::text(),'TEXT I Want')]

And no offense was taken, I am still pretty new to all the deeper black magic. My hardest part is the page I am testing doesn't have </input> tags.I guess a better question would have been "is there a website that lists more examples using xpath" The examples on the w3schools site don't really adequately show the power of xpath IMHO.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...