我正在使用 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;>
由于该元素具有 id 属性,因此我尝试使用其 id 值来定位它,但没有成功。
如果我在 Chrome 控制台中搜索该元素:
$('#screening_questions[0].multiple_choice[0]-dealbreakerField')
我得到异常: Uncaught DOMException:
Failed to execute '$' on 'CommandLineAPI': '#screening_questions[0].multiple_choice[0]-dealbreakerField' is not a valid selector.
我认为鉴于其 id 值,找到它会非常简单。您能建议这里可能出了什么问题吗?
这个错误信息...
Failed to execute '$' on 'CommandLineAPI': '#screening_questions[0].multiple_choice[0]-dealbreakerField' is not a valid selector.
...意味着定位策略你已经适应的是不是有效的选择器.
根据HTML您已共享所需的元素是<input>
标记为type
属性为checkbox
并使用id
你必须转义的属性.
字符,您可以使用以下选项之一:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)