量角器预期不存在于页面中
Protractor expect not exist in page
我有 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
(点击删除 link),然后我想检查 lorem2
删除 不应该 存在或包含在页面中。
我写了这段代码,但它不正确:
expect(element(by.css("table")).getText()).not.toBe('lorem2');
您将通过定位器删除 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);
我有 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
(点击删除 link),然后我想检查 lorem2
删除 不应该 存在或包含在页面中。
我写了这段代码,但它不正确:
expect(element(by.css("table")).getText()).not.toBe('lorem2');
您将通过定位器删除 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);