Element.text returns the text content of an element.
In a different thread on SO, the python script scrapes data from the followers modal on an Instagram account. The following part returns the text inside the lists and stores them in an array.
xpath = "//div[@style='position: relative; z-index: 1;']//ul/li/div/div/div/div/a"
followers_elems = driver.find_elements_by_xpath(xpath)
return [e.text for e in followers_elems]
I'm trying to achieve a similar result in JavaScript (I'm using WebDriverJS) :
const XPATH = "/html/body/div[3]/div/div[2]/div/div[2]/ul/div/li";
var followers_elems = await driver.findElements(By.xpath(XPATH));
var followers_temp = [];
for (var e in followers_elems) {
followers_temp.push(e.textContent); }
console.log(followers_temp);
I'm not sure if textContent is the right property for .text .
I've tried a million different alternatives but all I'm getting is undefined values in the array :
I'm not very proficient with JS yet, but I'm sure e
is reading from followers_elems
and if I push just e
inside the array it can log the total follower numbers just fine. It is getting the text value from xpath that I'm not understanding. Python does this so elegantly but despite the verbose JavaScript is failing me.
Thank you.