Selenium webdriver 无论是否找到元素,量角器交互(elementExplorer)都会显示结果

Selenium webdriver 无论是否找到元素,量角器交互(elementExplorer)都会显示结果,selenium-webdriver,protractor,getelementbyid,chrome-web-driver,Selenium Webdriver,Protractor,Getelementbyid,Chrome Web Driver,我的页面上有一个带有id的元素,即文本 当我运行量角器的elementExplorer时,即量角器。/config/dragrator-conf.js--elementExplorerhttp://localhost:9001,我键入元素(by.id('blablabla'))我得到一个元素结果(复制如下) 然而,我意识到,如果我给出任何愚蠢的id(即foo),我会得到似乎相同的结果。我希望收到错误或“未找到”消息。如何判断元素是否确实存在 每个元素(by.id())调用的结果: > el

我的页面上有一个带有id的元素,即文本

当我运行量角器的elementExplorer时,即
量角器。/config/dragrator-conf.js--elementExplorerhttp://localhost:9001
,我键入
元素(by.id('blablabla'))
我得到一个元素结果(复制如下)

然而,我意识到,如果我给出任何愚蠢的id(即
foo
),我会得到似乎相同的结果。我希望收到错误或“未找到”消息。如何判断元素是否确实存在

每个
元素(by.id())
调用的结果:

> element(by.id('foo'))
ElementFinder {
  ptor_:
   Protractor {
     getProcessedConfig: [Function],
     forkNewDriverInstance: [Function],
     restart: [Function],
     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],
     findElementsInternal_: [Function],
     takeScreenshot: [Function],
     manage: [Function],
     switchTo: [Function],
     driver:
      WebDriver {
        session_: [Object],
        executor_: [Object],
        flow_: [Object],
        fileDetector_: null },
     element: { [Function] all: [Function] },
     '$': [Function],
     '$$': [Function],
     baseUrl: 'http://localhost:9001',
     rootEl: 'body',
     ignoreSynchronization: false,
     getPageTimeout: 10000,
     params: {},
     ready:
      Promise {
        flow_: [Object],
        stack_: null,
        parent_: null,
        callbacks_: null,
        state_: 'fulfilled',
        handled_: true,
        value_: null,
        queue_: null },
     plugins_:
      Plugins {
        setup: [Function],
        teardown: [Function],
        postResults: [Function],
        postTest: [Function],
        onPageLoad: [Function],
        onPageStable: [Function],
        waitForPromise: [Function],
        waitForCondition: [Function],
        pluginObjs: [],
        assertions: {},
        resultsReported: false },
     resetUrl: 'data:text/html,<html></html>',
     trackOutstandingTimeouts_: true,
     mockModules_: [ [Object] ],
     allScriptsTimeout: 11000,
     dbgCodeExecutor_:
      { execPromise_: [Object],
        execPromiseResult_: undefined,
        execPromiseError_: undefined,
        replServer_: [Object],
        execute_: [Function],
        execute: [Function],
        complete: [Function],
        resultReady: [Function],
        getResult: [Function] } },
  then: null,
  parentElementArrayFinder:
   ElementArrayFinder {
     ptor_:
      Protractor {
        getProcessedConfig: [Function],
        forkNewDriverInstance: [Function],
        restart: [Function],
        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],
        findElementsInternal_: [Function],
        takeScreenshot: [Function],
        manage: [Function],
        switchTo: [Function],
        driver: [Object],
        element: [Object],
        '$': [Function],
        '$$': [Function],
        baseUrl: 'http://localhost:9001',
        rootEl: 'body',
        ignoreSynchronization: false,
        getPageTimeout: 10000,
        params: {},
        ready: [Object],
        plugins_: [Object],
        resetUrl: 'data:text/html,<html></html>',
        trackOutstandingTimeouts_: true,
        mockModules_: [Object],
        allScriptsTimeout: 11000,
        dbgCodeExecutor_: [Object] },
     locator_:
      name(name) {
          return By.css('*[name="' + escapeCss(name) + '"]');
        } { using: 'css selector', value: '*[id="blabla"]' },
     actionResults_: null,
     getWebElements: [Function],
     click: [Function],
     sendKeys: [Function],
     getTagName: [Function],
     getCssValue: [Function],
     getAttribute: [Function],
     getText: [Function],
     getSize: [Function],
     getLocation: [Function],
     isEnabled: [Function],
     isSelected: [Function],
     submit: [Function],
     clear: [Function],
     isDisplayed: [Function],
     getOuterHtml: [Function],
     getInnerHtml: [Function],
     getId: [Function],
     getRawId: [Function],
     serialize: [Function],
     takeScreenshot: [Function] },
  elementArrayFinder_:
   ElementArrayFinder {
     ptor_:
      Protractor {
        getProcessedConfig: [Function],
        forkNewDriverInstance: [Function],
        restart: [Function],
        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],
        findElementsInternal_: [Function],
        takeScreenshot: [Function],
        manage: [Function],
        switchTo: [Function],
        driver: [Object],
        element: [Object],
        '$': [Function],
        '$$': [Function],
        baseUrl: 'http://localhost:9001',
        rootEl: 'body',
        ignoreSynchronization: false,
        getPageTimeout: 10000,
        params: {},
        ready: [Object],
        plugins_: [Object],
        resetUrl: 'data:text/html,<html></html>',
        trackOutstandingTimeouts_: true,
        mockModules_: [Object],
        allScriptsTimeout: 11000,
        dbgCodeExecutor_: [Object] },
     locator_:
      name(name) {
          return By.css('*[name="' + escapeCss(name) + '"]');
        } { using: 'css selector', value: '*[id="blabla"]' },
     actionResults_: null,
     getWebElements: [Function],
     click: [Function],
     sendKeys: [Function],
     getTagName: [Function],
     getCssValue: [Function],
     getAttribute: [Function],
     getText: [Function],
     getSize: [Function],
     getLocation: [Function],
     isEnabled: [Function],
     isSelected: [Function],
     submit: [Function],
     clear: [Function],
     isDisplayed: [Function],
     getOuterHtml: [Function],
     getInnerHtml: [Function],
     getId: [Function],
     getRawId: [Function],
     serialize: [Function],
     takeScreenshot: [Function] },
  click: [Function],
  sendKeys: [Function],
  getTagName: [Function],
  getCssValue: [Function],
  getAttribute: [Function],
  getText: [Function],
  getSize: [Function],
  getLocation: [Function],
  isEnabled: [Function],
  isSelected: [Function],
  submit: [Function],
  clear: [Function],
  isDisplayed: [Function],
  getOuterHtml: [Function],
  getInnerHtml: [Function],
  getId: [Function],
  getRawId: [Function],
  serialize: [Function],
  takeScreenshot: [Function] }
元素(by.id('foo')) 元素查找器{ ptor_u2; 量角器{ getProcessedConfig:[函数], forkNewDriverInstance:[函数], 重新启动:[函数], controlFlow:[函数], 附表:[职能], setFileDetector:[函数], getSession:[函数], getCapabilities:[函数], 退出:[函数], 动作:[功能], touchActions:[函数], executeScript:[函数], executeAsyncScript:[函数], 调用:[函数], 等待:[函数], 睡眠:[功能], getWindowHandle:[函数], getAllWindowHandles:[函数], getPageSource:[函数], 关闭:[函数], getCurrentUrl:[函数], getTitle:[函数], findElementInternal:[函数], findElementsInternal:[函数], 截图:[函数], 管理:[职能], 切换到:[函数], 司机: 网络驱动程序{ 会话:[对象], 执行者:[对象], 流程:[对象], fileDetector_u3;:null}, 元素:{[Function]all:[Function]}, “$”:[函数], “$$”:[函数], baseUrl:'http://localhost:9001', 罗特尔:“身体”, ignoreSynchronization:false, getPageTimeout:10000, 参数:{}, 就绪: 允诺{ 流程:[对象], 堆栈:null, 父项:null, 回调:null, 声明:“已完成”, 答:对,, 值:null, 队列:null}, 插件: 插件{ 设置:[函数], 拆卸:[功能], postResults:[函数], 后测试:[函数], onPageLoad:[函数], onPageStable:[函数], waitForPromise:[函数], waitForCondition:[函数], pluginObjs:[], 断言:{}, resultsReported:false}, resetUrl:“数据:文本/html,”, TrackOutstanding超时:正确, mockModules:[[Object]], 所有脚本时间:11000, dbgCodeExecutor_389;: {execPromise:[对象], 执行提示结果:未定义, execPromiseError:未定义, replServer:[对象], 执行[Function], 执行:[函数], 完成:[函数], 结果:[函数], getResult:[函数]}}, 然后:空, parentElementArrayFinder: 元素阵列索引器{ ptor_u2; 量角器{ getProcessedConfig:[函数], forkNewDriverInstance:[函数], 重新启动:[函数], controlFlow:[函数], 附表:[职能], setFileDetector:[函数], getSession:[函数], getCapabilities:[函数], 退出:[函数], 动作:[功能], touchActions:[函数], executeScript:[函数], executeAsyncScript:[函数], 调用:[函数], 等待:[函数], 睡眠:[功能], getWindowHandle:[函数], getAllWindowHandles:[函数], getPageSource:[函数], 关闭:[函数], getCurrentUrl:[函数], getTitle:[函数], findElementInternal:[函数], findElementsInternal:[函数], 截图:[函数], 管理:[职能], 切换到:[函数], 驱动程序:[对象], 元素:[对象], “$”:[函数], “$$”:[函数], baseUrl:'http://localhost:9001', 罗特尔:“身体”, ignoreSynchronization:false, getPageTimeout:10000, 参数:{}, 就绪:[对象], 插件:[对象], resetUrl:“数据:文本/html,”, TrackOutstanding超时:正确, mockModules:[对象], 所有脚本时间:11000, dbgCodeExecutor_389;:[对象]}, 定位器: 姓名(姓名){ 按.css('*[name=“'+escapeCss(name)+'“]')返回; }{使用:'css选择器',值:'*[id=“blablabla”]'}, actionResults:空, getWebElements:[函数], 单击:[函数], sendKeys:[函数], GetTaName:[函数], getCssValue:[函数], getAttribute:[函数], getText:[函数], getSize:[函数], getLocation:[函数], isEnabled:[函数], isSelected:[功能], 提交:[功能], 清除:[函数], 显示:[函数], getOuterHtml:[函数], getInnerHtml:[函数], getId:[函数], getRawId:[函数], 序列化:[函数], 截图:[函数]}, 元素阵列索引器: 元素阵列索引器{ ptor_u2; 量角器{ getProcessedConfig:[函数], forkNewDriverInstance:[函数], 重新启动:[函数], controlFlow:[函数], 附表:[职能], setFileDetector:[函数], getSession:[函数], getCapabilities:[函数], 退出:[函数], 动作:[功能], touchActions:[函数], executeScript:[函数], executeAsyncScript:[函数], 调用:[函数], 等待:[函数], 睡眠:[功能], getWindowHandle:[函数], getAllWindowHandles:[函数], 获取页面
> element(by.id('something_that_does_not_exist')).getText()