Reputation: 339
There are a dynamic number of div containers on the page with the class name 'sponge', I need to loop through these and then get details from each one, but I can't figure out how to do this. This is what I've tried so far...
const containers = await driver.findElements(By.className(`sponge`))
for(let t = 0; t < containers.length; t++){
let runner = await containers[t].findElement(By.xpath(`//div[2]/div[1]/div/p`)).getText()
console.log(runner)
}
When I do this I just get the 'runner' in the first 'sponge' class container x amount of times, with x being the length of 'contaniers'. It doesn't actually find the 'runner' that is in the contanier I want
Upvotes: 2
Views: 1603
Reputation: 94
request
, got
, axios
, node-ferch
they will send a http request to the page and will getting back you the page html then you can use a module like jquery-jsdom
to get the dom object of the response element then you can access anything you wants to by jQuery selectors.Upvotes: 0
Reputation: 33384
To get the immediate child node
for parent node
you need to use .
try now.
const containers = await driver.findElements(By.className("sponge"))
for(let t = 0; t < containers.length; t++){
let runner = await containers[t].findElement(By.xpath(".//div[2]/div[1]/div/p")).getText()
console.log(runner)
}
Upvotes: 2