使用量角器获取背景颜色
Obtain background colour using protractor
我是量角器的新手,我想做的是获得元素的背景颜色。
到目前为止,我有:
var colour = element(by.css("div[class='ng-isolate-scope my-form']")).getCssValue('background-color');
console.log(colour);
我试过使用"背景色"answers"背景颜色"。
上述控制台日志如下
...{ 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才能获得值。如果您想使用console.log打印它,请执行以下操作:
$('div.my-form').getCssValue('background-color').then(function(bgColor) {
console.log(bgColor);
});
只是添加到@Andres的答案中,并考虑到:
我所追求的只是元素的背景颜色,然后我会将其与我认为应该是的颜色进行比较
由于您需要比较背景颜色,请注意,Protractor中的expect()
知道什么是promise,并且可以在进行期望检查之前明确解决它。换句话说,如果您只需要比较promise的已解析值,则不需要使用then()
:
expect($('div.my-form').getCssValue('background-color')).toEqual("rbga(255, 255, 255)");
相关文章:
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何使用jquery更改html中的背景颜色
- Javascript对象类在单击时打开窗口进行颜色选择,并在更改时替换对象背景颜色
- JS幻灯片与CSS背景颜色变化
- DT数据表背景颜色为黑色,但仍有悬停和选择颜色
- Javascript通过列表项的函数和css来更改背景颜色
- Javascript没有从数组中选择背景颜色
- 使用圆中的数组更改背景颜色项目
- 如何用jquery动画改变背景颜色,就像一个过渡
- 使用jquery交换并保存背景颜色
- j查询如何设置/取消设置下拉菜单的背景颜色
- 使用angularjs根据时间更改背景颜色
- 设置Dojo量表的背景颜色
- javascript样式的背景颜色在设置时闪烁.ASP.NET
- 使用javascript更改任意文本的背景颜色
- 在用Javascript更改背景颜色后:hover don'不要改变颜色
- 图像内部的透明背景颜色不受影响
- jQuery mobile-动态更改ui页面背景颜色
- 切换按钮的背景颜色
- JavaScript更改类的背景颜色