html - 通过ClassName定位后获取元素的XPath
问题描述
在通过 ClassName 定位元素后,我需要获取元素的 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)
推荐阅读
- api - 通过api将批量数据上传到branch.io
- javascript - 根据在选择/下拉框中而不是复选框中选择的值动态获取和显示地图图层
- java - 在Java中,我应该如何命令一个二维点沿着距离矢量线移动到另一个点?
- r - 从两个数据帧中采样相同数量的不平衡类
- apache-spark - 为什么 Spark Dstream 的 foreachRDD 在由于异常而停止之前会继续处理更多的微批处理?
- python - 主键和外键 Django Rest Framework 的嵌套 JSON 输出
- c# - 如何防止 C# WinForm listview 选择 Change when key is press and list view auto find next row on the based on the first column
- multithreading - 使用 .net 5 与任务(不是线程)的 TCP 连接
- python - 我如何制作 TinyDB 文件
- laravel - 我想使用 laravel 7 将多个图像下载为 zip 文件