我的页面上有一个带有 id 的元素,即<p id="blabla">The Text</p>
当我运行量角器的 elementExplorer 时,即protractor ./config/protractor-conf.js --elementExplorer http://localhost:9001
输入,element(by.id('blabla'))
我得到一个元素结果(复制如下)。
但是,我意识到,如果我给出任何愚蠢的 id (ie foo
),我会得到看似相同的结果。我期待收到错误或“未找到”消息。如何判断元素是否实际存在?
每次 element(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] }