I want to get HTML table data to cover to array by using selenium and Javascript. I test below code and I can get console.log(lm) in the for loop, but it shows array each loop.
the wepage is https://www.scoresandodds.com/mlb and click Game Details-->Line Movement
How I can get array(lm) at the end of the code? why I can not get any data in my code ?
console.log("Line Movement=================================\n");
driver.findElement(By.xpath('//*[@id="line-movements-tab--65040"]/span')).click(); //Line Movement
await driver.sleep(2500);
let rowC = '';
driver.findElements(By.xpath('//*[@id="line-movements--65040"]/div/table/tbody/tr')).then( function(rows){
console.log("[" + rows.length + "]" + "\n\n");
rowC = rows.length;
});
var lm=[];
for (i=0; i<rowC; i++) {
for (s=1; s<5; s++) {
var addCellText=function(elem, doneCallback){
elem.getText().then(function(textValue){
driver.sleep(1000);
lm.push(textValue);
return doneCallback(null);
});
};
xpath='//*[@id="line-movements--65040"]/div/table/tbody/tr[' + i + ']/td[' + s + ']';
driver.findElements(By.xpath(xpath)).then(function(elem){
async.each(elem, addCellText, function(error){
driver.sleep(1000);
//console.log(lm);
});
});
}
}
console.log("lm");
console.log(lm);
each team has a different code such as 65040, please look at each games code in the html. For example today(5/30) ARI-ATL of the code is 65051.