Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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/3/reactjs/24.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
Html 获取一个元素';在通过类名定位XPath之后_Html_Selenium_Selenium Webdriver_Xpath - Fatal编程技术网

Html 获取一个元素';在通过类名定位XPath之后

Html 获取一个元素';在通过类名定位XPath之后,html,selenium,selenium-webdriver,xpath,Html,Selenium,Selenium Webdriver,Xpath,通过类名定位元素后,我需要获取元素的XPath。 while (driver.FindElements(By.ClassName("N_elemt")).Count() > 0)  {  var result = driver.FindElement(By.ClassName("N_element"));  result = XPath of N_element ;  Console.WriteLine(result);   }  我正在使用C#项目。 谢谢我试试这个: var t

通过类名定位元素后,我需要获取元素的XPath。

while (driver.FindElements(By.ClassName("N_elemt")).Count() > 0) 
{ 
var result = driver.FindElement(By.ClassName("N_element")); 
result = XPath of N_element ; 
Console.WriteLine(result);  

} 


我正在使用C#项目。
谢谢

我试试这个:

var temp = driver.FindElement(By.XPath("name(//*[@ClassName='N_elemt'][1])"));

但是,很抱歉,我收到了此错误:

invalid selector: Unable to locate an element with the xpath expression name(//*[@ClassName='N_elemt'][1]) because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
  (Session info: chrome=80.0.3987.149)

我试试这个:

var temp = driver.FindElement(By.XPath("name(//*[@ClassName='N_elemt'][1])"));

但是,很抱歉,我收到了此错误:

invalid selector: Unable to locate an element with the xpath expression name(//*[@ClassName='N_elemt'][1]) because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
  (Session info: chrome=80.0.3987.149)


由于使用findElement,因此结果的大小等于1。首先,尝试使用:
temp=driver.findElement(By.xpath(“name(/*[@class=“N_elemt”][1]))
获取元素名,然后对结果进行concat(我不使用C):concat'/'&temp&'[@class=“N_elemt”]”生成xpath。由于使用findElement,结果的大小等于1。首先,尝试使用:
temp=driver.findElement(By.xpath(“name(/*[@class=“N_elemt”][1]))