【发布时间】:2019-07-15 06:09:44
【问题描述】:
只是想分享:如果您处于某个部分中没有类并且该特定 div 的值无法硬编码和更改的情况,使用量角器 e2e 框架我已经设法使用这个找到特定的 div方法:
添加一个没有每个元素都有一个类的html示例
<div class="row">
<div class="page_banner">A Dude's Profile</div>
<div class="profile_details">
<div class="profile_name">
<h3>Tony Adams</h3>
</div>
<div>ta@bogus.com</div>
<div>0883424324</div>
</div>
</div>
在需要说标识有唯一手机号的情况下,所以值不一致。
function mobileNumberAssert() {
element.all(by.css('.profile_details'))
.get(1) // number of divs in css
.getText()
.then(function(textFoundInCss) {
if(textFoundInCss > 10) {
return true;
console.log('there is a mobile number present with 10 digits');
} else {
return false;
}
});
}
对于调试,您可以通过控制台记录“textFoundInCss”以查找特定的 div。
【问题讨论】:
-
如果您提供一个呈现问题的 HTML 元素示例,这篇文章可能对其他人有用
-
@DublinDev 感谢您的推荐,我添加了一个 html 示例以便更好地理解。
-
看来你已经改变了这篇文章的原始内容。你有什么需要帮助的吗?
-
我只是想分享一个解决我遇到的问题的方法。我更新了这篇文章以包含一些示例 html,以更好地解释我的解决方案。
标签: css automation protractor element e2e-testing