Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XPath无效选择器错误_C#_.net_Xml_Xpath_Selenium - Fatal编程技术网

C# XPath无效选择器错误

C# XPath无效选择器错误,c#,.net,xml,xpath,selenium,C#,.net,Xml,Xpath,Selenium,我不明白为什么我的XPath语法中出现无效的选择器错误: 给定的选择器/*/tbody[@id='custContainer']/tr/td/a(以(@href'Customers/'开头)无效或未生成WebElement。出现以下错误: [InvalidSelectorError]由于以下错误,无法找到xpath表达式为/*/tbody[@id='dgContainer']/tr/td/a(以(@href'Customers/')开头)的元素。: [异常…”表达式不是合法表达式。“代码:“51

我不明白为什么我的XPath语法中出现无效的选择器错误:

给定的选择器
/*/tbody[@id='custContainer']/tr/td/a(以(@href'Customers/'开头)
无效或未生成WebElement。出现以下错误: [InvalidSelectorError]由于以下错误,无法找到xpath表达式为
/*/tbody[@id='dgContainer']/tr/td/a(以(@href'Customers/')开头)的元素。
: [异常…”表达式不是合法表达式。“代码:“51”nsresult:“0x805b0033(NS_错误\u DOM_无效\u表达式\u错误)”位置:resource://fxdriver/modules/atoms.js 行:2398“]

这是我在Selenium中使用By.XPath进行的一个调用。我还尝试了//而不是/*/作为该路径的开始,但不确定使用哪一个…不确定这是问题所在,或者它是否是我字符串的其他部分

我还尝试了contains而不是start with


仅供参考,我不熟悉Selenium和XPath….

您的XPath表达式肯定不正确。请在方括号中定义谓词,即:

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

简化。每次使用XPath时,我都会从尽可能广泛的查询开始,以确保获得结果,然后再进行优化。从/*/tbody开始,并以增量方式添加。可能您需要
a[以(@href,'Customers/')]
(注意方括号)感谢n8wl的建议,我也开始明白了。我不太清楚XPath是如何工作的……这很有意义,但我必须习惯它在dom中的运行方式,它的期望值等等。您似乎依赖于反复试验。这不是一个好策略。这是最后一个对我有效的XPath字符串。Format(//tbody[@id='custContainer']/tr/td/a[(包含(@href,{0}'))],“/Customer/”;