I am looping through a drop down list and I am trying to select individual options. If I try to use a template literal, the querySelector returns null.
Here are two different queries, one with a template literal and one without. I am using back ticks and everything is the same but the first query returns null while the second one returns the right value even though "i" = 2 in this case.
const value = await self.page.evaluate(() => {
return document.querySelector(`select option:nth-child(${i})`);
});
const value1 = await self.page.evaluate(() => {
return document.querySelector(`select option:nth-child(2)`);
});
// Structure
for (let i = 2; i < options.length; i++){
if (options[i]....){
const value = await self.page.evaluate((i) => {
return document.querySelector(`select option:nth-child(${i})`);
});
}
}
Why is this happening?