【问题标题】:Protractor expect not exist in page量角器期望页面中不存在
【发布时间】:2018-08-15 06:12:12
【问题描述】:

我有这样的html页面:

<table>
<thead>
    <tr>
        <td>title</td>
        <td>desc</td>
        <td>status</td>
    </tr>
</thead>
<tbody>
    <tr>
        <td><label>lorem1</label></td>
        <td><label>desc1 lorem</label></td>
        <td><label>active</label></td>
        <td><a href="http://example.com/post/1/delete"> Delete </a></td>
    </tr>
    <tr>
        <td><label>lorem2</label></td>
        <td><label>desc2 lorem</label></td>
        <td><label>active</label></td>
        <td><a href="http://example.com/post/2/delete"> Delete </a></td>
    </tr>
    <tr>
        <td><label>lorem3</label></td>
        <td><label>desc3 lorem</label></td>
        <td><label>deactive</label></td>
        <td><a href="http://example.com/post/3/delete"> Delete </a></td>
    </tr>   
</tbody>
</table>

现在我从上面的列表中删除记录lorem2(点击删除链接),然后我想检查lorem2删除的不应该存在或包含在页面中。

我写了这段代码,但它不正确:

expect(element(by.css("table")).getText()).not.toBe('lorem2');

【问题讨论】:

  • 您正在使用 CSS 选择器。为什么要添加 XPath 标签?\
  • 我想也许这个问题可以用 Xpath 解决

标签: xpath protractor e2e-testing


【解决方案1】:

您将删除lorem2 的定位器可能是xpath

以下为删除

//tr/td//label[contains(text(),"lorem2")]/following::td/a

删除后检查是否存在

//tr/td//label[contains(text(),"lorem2")]

您应该将 xpath (i.e) 文本 Lorem2 参数化为其他文本。

expect(element(by.xpath('//tr/td//label[contains(text(),"lorem2")]
')).isPresent()).toBe(false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 2019-08-08
    相关资源
    最近更新 更多