未捕获的DOMException:无法在'CommandLineAPI'上执行'$':无效的选择器 [英] Uncaught DOMException: Failed to execute '$' on 'CommandLineAPI': not a valid selector
问题描述
我正在使用selenium为我的网页编写自动化UI测试。
我正在测试的网页上有一个元素:
I am writing automation UI tests for my web page using selenium. I have an element on the web page which I am testing:
<< input type="checkbox" id="screening_questions[0].multiple_choice[0]-dealbreakerField" value="on" style="position: absolute; cursor: inherit; pointer-events: all; opacity: 0; width: 100%; height: 100%; z-index: 2; left: 0px; box-sizing: border-box; padding: 0px; margin: 0px;>
由于该元素具有id属性,因此我尝试使用其id值来定位它,但是它不起作用。
Since the element has id attribute, so I tried to locate it by using its id value but it didn't work.
如果我在chrome控制台中搜索该元素,则为:
If I search for that element in chrome console as:
$('#screening_questions[0].multiple_choice[0]-dealbreakerField')
我得到了例外:未捕获的DOMException:
I get the exception: Uncaught DOMException:
Failed to execute '$' on 'CommandLineAPI': '#screening_questions[0].multiple_choice[0]-dealbreakerField' is not a valid selector.
我认为找到我会很简单给定其id值。
I thought it will be pretty straight forward to locate it given its id value. Could you please suggest what could be wrong here?
推荐答案
此错误消息...
Failed to execute '$' on 'CommandLineAPI': '#screening_questions[0].multiple_choice[0]-dealbreakerField' is not a valid selector.
...表示您采用的定位器策略 不是有效的选择器。
根据您共享的 HTML ,所需的元素是带有的
属性作为 < input>
标记类型复选框
,并使用 id
属性您必须转义。
字符,然后可以使用以下任一选项:
As per the HTML you have shared the desired element is a <input>
tag with type
attribute as checkbox
and to use the id
attribute you have to escape the .
characters and you can use either of the following options :
-
cssSelector :
"input[id=\"screening_questions[0].multiple_choice[0]-dealbreakerField\"][type='checkbox']"
xpath :
"//input[@id=\"screening_questions[0].multiple_choice[0]-dealbreakerField\"][@type='checkbox']"
这篇关于未捕获的DOMException:无法在'CommandLineAPI'上执行'$':无效的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!