我正在使用 selenium 为我的网页编写自动化 UI 测试。我正在测试的网页上有一个元素:
<< 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;>
Run Code Online (Sandbox Code Playgroud)
由于该元素具有 id 属性,因此我尝试使用其 id 值来定位它,但没有成功。
如果我在 chrome 控制台中搜索该元素为:
$('#screening_questions[0].multiple_choice[0]-dealbreakerField')
Run Code Online (Sandbox Code Playgroud)
我收到异常:未捕获的 DOMException:
Failed to execute '$' on 'CommandLineAPI': '#screening_questions[0].multiple_choice[0]-dealbreakerField' is not a valid selector.
Run Code Online (Sandbox Code Playgroud)
我认为根据它的 id 值可以很容易地找到它。你能建议这里有什么问题吗?