首页 > 解决方案 > 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

标签: seleniumdynamics-crm

解决方案


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


推荐阅读