c# - C# Selenium findElements by XPath returns null
问题描述
IList<IWebElement> firstname = driverOne.FindElements(By.XPath("//*[@id="+ ((char)34) + "4cd85da6-f2d1-4361-9864-e187dc763f9b" + ((char)34) + "]"));
I tried this go get the element from the HTML below, but it returns null, because everytime I reload the page the XPath gets changed, because the element gets created randomly from Angular, I think.
<input id="0bad9cfd-028d-404c-a498-17a3f5f1ae81" type="text" data-test="first-name-input" placeholder="" class="ng-untouched ng-pristine ng-invalid"><!----><!---->
I also tried to do it with the Id and the CSS-Selector, but everything is changed after a reload, so I dont know what do...
So how can I get the Element?
解决方案
当您将 ID 分配给 html 标记时,严格如下:
<h1 id="test"> </h1>
ID 在 Angular 渲染过程后不会改变。您可以将 ID 添加到您需要访问的每个元素。
推荐阅读
- python - 正则表达式删除(whatever_inside)IFF,如果括号内没有空格,则只有 IFF
- c++ - 程序在输出时卡住了
- android-studio - 源代码是否添加了从 Android 工作室获取的 APK
- ios - 如何在 Swift 中创建标签点下划线
- r - 为什么可以在 dplyr 辅助函数“across”中检测到 tidyselect 辅助函数“where”?
- node.js - AWS LAMBDA api 网关错误“格式错误的 Lambda 代理响应”状态错误 502
- python - 如何使日期列对 postgres 而不是 Python 中的数据探索更具吸引力?
- c# - 如何将自定义代码添加到在服务器上执行的 EFCore
- django - django-admin startproject 命令返回错误的解释器:没有这样的文件或目录
- dataframe - pyspark:如何填充列中的值并用另一个数据框的列替换条件