Html 获取一个元素';在通过类名定位XPath之后
通过类名定位元素后,我需要获取元素的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
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]))
。