Exploring the capabilities of webdriverIO has been quite enjoyable! There are many features of this framework that I already appreciate.
In my investigation, I wanted to see how WebdriverIO handles non-existing elements and lazy element loading in this test:
it('no element, and not used', () => {
browser.pause(5000)
let non_exist = browser.$('.nonexist')
});
The output from the test runner is as follows:
[17:23:25] COMMAND POST "/wd/hub/session/6b79fd07-5f5d-42ce-b1e5-f99734aae128/element"
[17:23:25] DATA {"using":"css selector","value":".nonexist"}
Reviewing the webdriver server log:
*** Element info: {Using=css selector, value=.nonexist}
17:23:25.840 INFO - Executing: [delete session: 6b79fd07-5f5d-42ce-b1e5-f99734aae128])
It appears that WebdriverIO still sends a POST request to the selenium server, attempting to locate the element upon declaration.
Let's now look at the second test. Here, I declare an element that does not exist on the page but try to use it later:
it('no element, used later in the code', () => {
browser.pause(5000)
let myElem = browser.$('.nonexist')
console.log('AND NOW FAIL!')
console.log(myElem.getText())
});
The output from the test runner for this scenario is:
[17:30:35] COMMAND POST "/wd/hub/session/05e4115c-ed66-4e47-8a01-c37208d379ab/element"
[17:30:35] DATA {"using":"css selector","value":".nonexist"}
AND NOW FAIL!
[17:30:36] COMMAND POST "/wd/hub/session/05e4115c-ed66-4e47-8a01-c37208d379ab/elements"
[17:30:36] DATA {"using":"css selector","value":".nonexist"}
[17:30:36] RESULT []
Looking at the Selenium Server logs:
*** Element info: {Using=css selector, value=.nonexist}
17:30:36.133 INFO - Executing: [find elements: By.cssSelector: .nonexist])
17:30:36.155 INFO - Done: [find elements: By.cssSelector: .nonexist]
Webdriver IO makes two requests - first during declaration, and then an 'elements' request when attempting to perform an action on the element.
The question arises, why does WebdriverIO attempt to find the element twice in these examples? Although no exceptions are thrown and everything seems to be working fine, I'm curious if this behavior is intentional or possibly a bug?