我需要验证电子邮件链接文本的颜色。 下面是我的代码:
it('Contact Text Validation', function(){
expect (Contact_info_on_Login_screen.isDisplayed())
var Email_Link = element(by.css("body > app-root > app-login > div > div > div > div > div > div.card-header.py-3.d-flex.justify-content-between.align-items-center > div > p > a:nth-child(1) > span:nth-child(1)"));
var Col_Email = (Email_Link.getCssValue('color')).then(function(){
browser.sleep(2000).then(function(){
console.log(" The color for Email Link is :" + Col_Email);
});
});
}
同一个元素的颜色在css属性中显示如下。
相关的html代码是<p _ngcontent-c1="" class="m-4"> Questions about filling in the report data or access to the application, please call <a _ngcontent-c1="" class="text-link-blue" href=""><span _ngcontent-c1="">Admin</span> / <span _ngcontent-c1=""> Manager</span></a> at <a _ngcontent-c1="" class="text-link-blue" href=""> 123-456-7890</a>. For software issues, email <a _ngcontent-c1="" class="text-link-blue" href="">other person</a> . </p>
当我运行它时,我从 Protractor 得到以下输出:
[13:58:52] I/hosted - Using the selenium server at http://localhost:4444/wd/hub Started The color for Email Link is :ManagedPromise::643 {[[PromiseStatus]]: "pending"}
我不确定我做错了什么。它应该返回颜色代码,而不是显示 promise 未决。
最佳答案
你错误地解决了一个 promise ,回调函数接收实际解决的值作为参数:
// v-----HERE-----v
Email_Link.getCssValue('color').then(function (actualColorValue) {
console.log("The color for Email Link is :" + actualColorValue);
});
关于javascript - 使用 Protractor 检索 css 颜色属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53822549/