1
votes

I can't see why I get an invalid selector error in my XPath syntax here:

The given selector /*/tbody[@id='custContainer']/tr/td/a(starts-with(@href, 'Customers/') is either invalid or does not result in a WebElement. The following error occurred: [InvalidSelectorError] Unable to locate an element with the xpath expression /*/tbody[@id='dgContainer']/tr/td/a(starts-with(@href, 'Customers/') because of the following error: [Exception... "The expression is not a legal expression." code: "51" nsresult: "0x805b0033 (NS_ERROR_DOM_INVALID_EXPRESSION_ERR)" location: "resource://fxdriver/modules/atoms.js Line: 2398"]

This is a call I'm doing in Selenium using By.XPath. I also tried // instead of /*/ for the start of that path but not sure which to use...not sure of that's the problem or if it's some other part of my string here.

I also tried contains instead of starts-with.

FYI I'm new to Selenium and XPath....

1
Simplify. Every time I struggle with XPath I start with the broadest query possible to ensure I get results and then refine. Start with /*/tbody and incrementally add on. - n8wrl
Probably you need a[starts-with(@href, 'Customers/')] (note the square brackets) - Igor Korkhov
thanks for the advice n8wl, I'm starting to see that too. I don't really know exactly how XPath works...it makes sense but I have to get used to how it walks the dom, what it expects, etc. - PositiveGuy
You seem to be relying on trial and error. Not a good strategy. - Michael Kay

1 Answers

0
votes

Definitely your XPath expression is incorrect. Define predicate in square brackets, i.e.:

/*/tbody[@id='custContainer']/tr/td/a[starts-with(@href, 'Customers/')]