I'm using Protractor (Angular JS's webdriver wrapper), and although I can chain findElement
indefinitely off of a single WebElement
instance, I get an error when I attempt to chain findElement
after using findElements
(plural).
Error (stack trace given at bottom):
TypeError: Object [object Object] has no method 'findElement'
Chaining findElement:
var elementPromise = browser.findElement(by.css('body')).findElement(by.css('ul')).findElement(by.css('li'));
elementPromise.findElement(by.css('.icon-meter')); // does not raise error
Using findElement after findElements:
var arrayPromise = browser.findElement(by.css('ul')).findElements(by.css('li'));
elementPromise = arrayPromise.then(function(elems) {
return elems[0];
});
elementPromise.findElement(by.css('.icon-meter')); // => raises error
Error message with trace
TypeError: Object [object Object] has no method 'findElement'
at repl:1:16
at /home/markham/src/dataraptor-rails4/spec/node_modules/elementexplorer-convenience.js:83:19
at webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1598:20)
at webdriver.promise.ControlFlow.runEventLoop_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1463:8)
at wrapper [as _onTimeout] (timers.js:252:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
The methods findElements and findElement are used to identify elements on a webpage. While findElement can pinpoint only one element, the findElements method yields a list of matching web elements. The return type of findElements is a list whereas the return type of findElement is a WebElement.
driver. findElement() is used to find a webElement on a webpage. driver. findElements() is used to find a List of webElements matching the locator passed as parameter.
FindElement would return you the first element within the web page which matches the locator value.
findElement: This command is used to uniquely identify a web element within the web page. findElements: This command is used to uniquely identify the list of web elements within the web page.
I got the same problem with the version 0.24 of protractor.
As a workaround, i have replaced all the invocation of findElement()
by element()
and all findElements()
by all()
.
Chaining element:
var elementPromise = browser.element(by.css('body')).element(by.css('ul')).element(by.css('li'));
elementPromise.element(by.css('.icon-meter'));
Using findElement after findElements:
var arrayPromise = browser.element(by.css('ul')).all(by.css('li'));
elementPromise = arrayPromise.then(function(elems) {
return elems[0];
});
elementPromise.element(by.css('.icon-meter'));
There is more details on this release in this g+ post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With