2

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

2 Answers 2

2

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)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, this is exactly what I needed!!!!
0
  • i suggest you to use another way to scraping this website you can try modules like 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.
  • scraping to extract data is better by http request

3 Comments

Is this better though for download amounts? wouldn't the download sizes be a lot higher?
Size of what? you need just to one of them you can use request, jquery-jsdom
No I mean the download amounts for the things that are being scraped, would it be better for the download sizes if I got the entire html of the page and then manipulated that in node? or if I just scraped the parts of the page that I need?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.