selenium - Nightwatch 无法通过 id 定位元素,单词之间有空格
问题描述
我使用 Nightwatch 来自动化 UI 测试,大多数时候我使用一个简单的 ID 选择器,例如:
<div data-testid="Phone" class="styles__Row-sc-1w30zs4-0 styles__CanonicalRow-sc-1w30zs4-1 class="styles__StyledInput-n24pwb-1 fryvby" value=""></div>
我在 Nightwatch 中找到了这个元素:[data-testid=Phone]
它工作得很好,但是我在定位这个元素时遇到了问题:
<div data-testid="Date of birth" class="styles__Row-sc-1w30zs4-0 styles__CanonicalRow-sc-1w30zs4-1 ijIenC" xpath="1"><div class="styles__StyledLabelContainer-sc-33nmzi-11 houBGy"><label for="190" class="styles__StyledLabel-sc-33nmzi-3 bAvMbu">Date of birth</label></div></div>
我尝试使用以下方法找到它:[data-testid=Date of birth]
但出现错误:“运行 .locateMultipleElements() 协议操作时出错:无效选择器:指定了无效或非法选择器”
我认为这是因为单词之间的空格可以帮助我找到这个元素吗?谢谢
解决方案
推荐阅读
- javascript - GraphQL:返回新的 Promise((resolve,object)
- ios - 如何在 Crashlytics 中使用 CLSStackFrame?
- webpage - 网页启动错误
- python - Google App Engine dev_appserver.py:watcher_ignore_re 标志“不是 JSON 可序列化的”
- r - R中的菊花功能警告
- java - Apache Maven:-source 1.5 中不支持 Diamond 运算符
- python-2.7 - Pycharm 后台任务永远占用
- c# - 如何像 C++ 一样在 C# 中初始化
- symfony - Doctrine ORM:使用更新级联选项手动添加 fk 来验证模式
- android - 所有 WebView 都以某种方式共享访问历史记录