ai didi

javascript - 使用 Protractor 获取背景颜色

转载 作者:行者123 更新时间:2023-12-03 09:49:23 24 4
gpt4 key购买 nike

我是 Protractor 的新手,我想做的是获取元素的背景颜色。

到目前为止我有:

var colour = element(by.css("div[class='ng-isolate-scope my-form']")).getCssValue('background-color');
console.log(colour);

我已经尝试过“背景颜色”和“背景颜色”。

上面的控制台日志如下

 ...{ ptor_: 
{ controlFlow: [Function],
schedule: [Function],
setFileDetector: [Function],
getSession: [Function],
getCapabilities: [Function],
quit: [Function],
actions: [Function],
touchActions: [Function],
executeScript: [Function],
executeAsyncScript: [Function],
call: [Function],
wait: [Function],
sleep: [Function],
getWindowHandle: [Function],
getAllWindowHandles: [Function],
getPageSource: [Function],
close: [Function],
getCurrentUrl: [Function],
getTitle: [Function],
findElementInternal_: [Function],
findDomElement_: [Function],
findElementsInternal_: [Function],
takeScreenshot: [Function],
manage: [Function],
switchTo: [Function],
driver:
Object {
session_: [Object],
executor_: [Object],
flow_: [Object],
fileDetector_: null },
element: { [Function] all: [Function] },
'$': [Function],
'$$': [Function],
baseUrl: '',
rootEl: 'body',
ignoreSynchronization: true,
getPageTimeout: 10000,
params: {},
ready:
Object {
closure_uid_262032795: 12,
flow_: [Object],
stack_: null,
parent_: null,
callbacks_: null,
state_: 'fulfilled',
handled_: true,
value_: null,
queue_: null },
plugins_:
{ pluginConfs: [],
pluginObjs: [],
assertions: {},
resultsReported: false },
resetUrl: 'data:text/html,<html></html>',
trackOutstandingTimeouts_: true,
mockModules_: [ [Object] ],
allScriptsTimeout: 11000,
getProcessedConfig: [Function],
forkNewDriverInstance: [Function],
restart: [Function] },
parentElementArrayFinder:
{ ptor_:
{ controlFlow: [Function],
schedule: [Function],
setFileDetector: [Function],
getSession: [Function],
getCapabilities: [Function],
quit: [Function],
actions: [Function],
touchActions: [Function],
executeScript: [Function],
executeAsyncScript: [Function],
call: [Function],
wait: [Function],
sleep: [Function],
getWindowHandle: [Function],
getAllWindowHandles: [Function],
getPageSource: [Function],
close: [Function],
getCurrentUrl: [Function],
getTitle: [Function],
findElementInternal_: [Function],
findDomElement_: [Function],
findElementsInternal_: [Function],
takeScreenshot: [Function],
manage: [Function],
switchTo: [Function],
driver: [Object],
element: [Object],
'$': [Function],
'$$': [Function],
baseUrl: '',
rootEl: 'body',
ignoreSynchronization: true,
getPageTimeout: 10000,
params: {},
ready: [Object],
plugins_: [Object],
resetUrl: 'data:text/html,<html></html>',
trackOutstandingTimeouts_: true,
mockModules_: [Object],
allScriptsTimeout: 11000,
getProcessedConfig: [Function],
forkNewDriverInstance: [Function],
restart: [Function] },
getWebElements: [Function],
actionResults_:
Object {
closure_uid_262032795: 4569,
flow_: [Object],
stack_: null,
parent_: [Object],
callbacks_: null,
state_: 'pending',
handled_: false,
value_: undefined,
queue_: null },
locator_: Object { using: 'css selector', value: 'body[class=\'ng-scope\']' } },
then: [Function],
elementArrayFinder_:
{ ptor_:
{ controlFlow: [Function],
schedule: [Function],
setFileDetector: [Function],
getSession: [Function],
getCapabilities: [Function],
quit: [Function],
actions: [Function],
touchActions: [Function],
executeScript: [Function],
executeAsyncScript: [Function],
call: [Function],
wait: [Function],
sleep: [Function],
getWindowHandle: [Function],
getAllWindowHandles: [Function],
getPageSource: [Function],
close: [Function],
getCurrentUrl: [Function],
getTitle: [Function],
findElementInternal_: [Function],
findDomElement_: [Function],
findElementsInternal_: [Function],
takeScreenshot: [Function],
manage: [Function],
switchTo: [Function],
driver: [Object],
element: [Object],
'$': [Function],
'$$': [Function],
baseUrl: '',
rootEl: 'body',
ignoreSynchronization: true,
getPageTimeout: 10000,
params: {},
ready: [Object],
plugins_: [Object],
resetUrl: 'data:text/html,<html></html>',
trackOutstandingTimeouts_: true,
mockModules_: [Object],
allScriptsTimeout: 11000,
getProcessedConfig: [Function],
forkNewDriverInstance: [Function],
restart: [Function] },
getWebElements: [Function],
actionResults_:
Object {
closure_uid_262032795: 4569,
flow_: [Object],
stack_: null,
parent_: [Object],
callbacks_: null,
state_: 'pending',
handled_: false,
value_: undefined,
queue_: null },
locator_: Object { using: 'css selector', value: 'body[class=\'ng-scope\']' } } }

我所追求的只是元素背景颜色,然后我会将其与我认为应该的颜色进行比较。

我要获取背景颜色的元素是

<div class="ng-isolate-scope my-form" ng-show="!model.loading && activeTab == 'form' && model.formData != null && model.formData != undefined" ng-class="model.formData.className" auto-height="" style="height: 144px;">

我们将不胜感激与此相关的任何帮助。

最佳答案

您需要解决 promise 以获得值(value)。如果您想使用 console.log 打印它,请执行以下操作:

$('div.my-form').getCssValue('background-color').then(function(bgColor) {
console.log(bgColor);
});

关于javascript - 使用 Protractor 获取背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34614442/

24 4 0
文章推荐: python-3.x - 构建新数据框并保留旧数据框?
文章推荐: javascript - latlng函数参数
文章推荐: nhibernate - 如何将 Skip 和 Take 附加到 nHibernate IQueryOver
文章推荐: bower - 为什么 Bower 会返回 410 错误消息?
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com