views:

37

answers:

1

So I'm trying to check the XPath of a block of text to verify that the correct page has been returned. However, for the several sites and designs I'm testing(with Selenium 2), the block of text I'm searching for is always the same, but the XPath to it is always different(the block of text has no defining ID or Class, so I need to check the text). Is there a simple way to scan for the particular text, without having to write logic that will try node after node until it finds the text(or just fails)?

+1  A: 

How about something like this:

//*[contains(text(), 'text you want to find')]

(I assume you have to use XPath? Personally I prefer LINQ to XML where it's feasible, but presumably you're giving the XPath expression to Selenium...)

Jon Skeet
Thanks! I'm gonna give that a shot. I was only using Xpath since Selenium 2 has a built method for it, but could you please elaborate on LINQ to XML(I'm still new to .Net)? It doesnt NEED to be Xpath.
James
@James: LINQ to XML is an XML API introduced in .NET 3.5. I *suspect* XPath is the better approach here, unless Selenium exposes the DOM in LINQ to XML as well.
Jon Skeet
@Jon, thanks! That XPath solution worked perfectly!!
James