当前位置:  开发笔记 > 编程语言 > 正文

使用量角器获得背景颜色

如何解决《使用量角器获得背景颜色》经验,为你挑选了1个好方法。

我是量角器的新手,我想做的是获取元素的背景颜色.

到目前为止,我有:

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

我试过'background-color'和'background-color'.

上述控制台日志如下

 ...{ 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,',
     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,',
        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,',
        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\']' } } }

所有我追求的是元素背景颜色,然后我将与我认为它应该是比较.

我试图获得背景颜色的元素是

任何有关这方面的帮助将非常感谢.



1> Andres D..:

您需要解决获得价值的承诺.如果要使用console.log打印它,请执行以下操作:

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

推荐阅读
重庆制造漫画社
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有