简体   繁体   中英

XPath Invalid Selector Error

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....

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM