selenium - InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text() error message
问题描述
I'm getting this error message when selenium/C# program tried to click on an element in a drop down list in Dynamis365.
Inner Exception 1: InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text(), 'Submitted') 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=87.0.4280.88)
My Code is:
internal void SetValues()
{
findByElement.FindByXPath("//span[contains(text(), 'Submission Pending')]").Click();
findByElement.FindByXPath("contains(text(), 'Submitted')").Click();
}
The HTML is:
<span id="id-bc19d003-2d6a-43ad-8e1b-566ecbb00647-132-statuscode6-statuscode.fieldControl-pickliststatus-comboBox_text-value" class=" ">Submission Pending</span>
I'm trying to click on Submitted choice, which do not show in HTML:DropDownList
Note: The other drop down list choices do not show in html. Only after making a choice (Submitted) it shows up in the html (replaces Submission Pending") Submission Pending Submitted clicked
解决方案
Are you sure the page has fully loaded? Have you read the docs, specifically the 'waits' section (link below for the python version). I had this problem and simply put a 5 second delay into the code and it worked fine.
https://selenium-python.readthedocs.io/waits.html
Alternatively you may find it easier locating the element by id rather than by XPath
推荐阅读
- angular - 为什么在 ngAfterContentInit() 中使用 setTimeOut,0?
- r - 从另一个数据帧在 dplyr 中创建模拟数据帧
- wso2 - 如何从 wso2 正确地向 rabbitmq 发送消息?
- python - 在 Pandas 中将多列乘以固定值
- python - 如何使用 Python 按键顺序检索 Redis 数据库值
- clojure - clojure ubergraph 编译错误 - 'namespace'ubergraph.core' 未找到
- php - 手动安装phpoffice
- python - BrokenPipeError:[Errno 32] 损坏的管道,python
- javascript - 如何使用类型捕获无效的序列化数据输入
- jspdf-autotable - 带有 CSS 样式的 HTML 表格的 Autotable