protractor - 量角器期望选择器的特定文本兄弟
问题描述
我有一张这样的桌子:
<table>
<tbody>
...
<tr>
<td>
<div class="radio-inline">
<input name="sms_provider" type="radio" value="2" id="2">
<label class="text-gray-dark" for="2"> </label>
</div>
</td>
<td data-label="Server name">ServerA3</td>
<td data-label="Description"></td>
<td data-label="Status">
<label class="text-success">
<clr-icon shape="check"></clr-icon>
Default
</label>
</td>
<td data-label="Actions">
<a href="http://example.com/public/smsconfigurations/2/edit" data-tooltip="Edit Server">
<clr-icon shape="pencil" size="22" style="width: 22px; height: 22px;"></clr-icon>
</a>
</td>
</tr>
...
</tbody>
</table>
现在我想检查是否ServerA3
有Default
状态。事实上,我希望ServerA3
有Default
文本作为兄弟姐妹。我应该怎么办?
我尝试使用此代码,但它不起作用:
expect(element(by.xpath('//td[contains(text(), "ServerA3")]')).getWebElement().getDriver().findElement(by.css('*[data-label="status"]')).getText()).toContain('Default');
解决方案
var status = element(by.xpath('//tr[td[.="ServerA3"]]/td[@data-label="Status"]'))
.getAttribute('innerText');
expect(status).toEqual('Default')
推荐阅读
- java - dbutils.fs.ls 在过滤器中返回 FileNotFoundException 异常
- kotlin - 在新安装的 IntelliJ IDEA 中使用默认设置创建新的 Kotlin 项目时,Gradle 同步失败
- google-sheets - 谷歌表格下拉更改自动基于单元格值
- javascript - 对于基于应用程序的在线商店,我应该使用原生应用程序还是混合应用程序
- css - 如何覆盖 Storybook 内容中的降价样式?
- sed - 用 sed 对数字进行分组:下划线对我不起作用
- python - Python正则表达式替换数字-1
- reactjs - 如何从反应中允许python烧瓶socketio中的cors-origin-policy
- django - 如何在外键属性limit_choice_to中使用模型字段名称
- django - 如何使用 django rest 框架根据子数据过滤父数据?