score:6

Accepted answer

getallby

getallby* queries return an array of all matching nodes for a query, and throw an error if no elements match.

queryallby

queryallby* queries return an array of all matching nodes for a query, and return an empty array ([]) if no elements match.

query cheetsheet

enter image description here

use the query variant so as not to throw in a test if no matches found, and use queryselectorall since queryselector returns only the first element that matches, or null.

const element = queryallbytestid("add");
if (element.length) {
  let divs = element[0].queryselectorall("div");
  // ...get the div node you need
}

you can even specify divs with a specific class

const element = queryallbytestid("add");
if (element.length) {
  let divs = element[0].queryselectorall("div.icon");
  // ...get the div node you need
}

Related Query

More Query from same tag