Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to findElements from a returned findElement in selenium javascript

Its general knowledge that in Java, the easiest way to accomplish this is by

List <WebElement> listItems=findElement(by.selector(selector)).findElements(by.selector(selector));

The question is how do you accomplish this in Javascript. I have searched online to no avail.

I use Selenium-Mocha-chai.

like image 852
Kermit_ice_tea Avatar asked Apr 13 '26 23:04

Kermit_ice_tea


1 Answers

Javascript is asynchronous, and doing it via promises, it would something like:

var listItems;
driver.findElement(By.selector(selector))
  .then(function(element){
    return element.findElements(By.selector(selector2));
  }).then(function(elements){
    listItems=elements;
    // do some stuff...
  }).catch(function(e){ // error handler
    console.error(e);
  })
like image 130
mido Avatar answered Apr 16 '26 13:04

mido