简体   繁体   中英

selenium webdriver getText Returns [object object]

I have a selenium script that is supposed to grab the text from the table columns after the cell that contains the desired value.

I have the script working but for some reason when I run getText() and check the value that is returned I get [Object Object] in my node.js console... I am confused I have tried to parse it as a string, I have called the getText() on the variable that would be the element and several other ways but to no avail...

Here is the section of my script in question:

if(tempID!=1){
//tr[contains(td[1], "ID#")]/td[#]  
scrapeArray[0] = tempID;
console.log(scrapeArray[0]);
}
}).then(function(){
scrapeArray[1] = String(driver.findElement(webdriver.By.xpath('//tr[contains(td[1], "'+tempID+'")]/td[2]')).text());
console.log("1: "+scrapeArray[1]);
}).then(function(){
scrapeArray[2] = String(driver.findElement(webdriver.By.xpath('//tr[contains(td[1], "'+tempID+'")]/td[3]')).text());
console.log("2: "+scrapeArray[2]);
}).then(function(){
scrapeArray[3] = String(driver.findElement(webdriver.By.xpath('//tr[contains(td[1], "'+tempID+'")]/td[4]')).text());
console.log("3: "+scrapeArray[3]);
}).then(function(){
scrapeArray[4] = String(driver.findElement(webdriver.By.xpath('//tr[contains(td[1], "'+tempID+'")]/td[5]')).text());
console.log("4: "+scrapeArray[4]);
}).then(function(){
scrapeArray[5] = String(driver.findElement(webdriver.By.xpath('//tr[contains(td[1], "'+tempID+'")]/td[6]')).text());
console.log("5: "+scrapeArray[5]);
}).then(function(){
scrapeArray[6] = String(driver.findElement(webdriver.By.xpath('//tr[contains(td[1], "'+tempID+'")]/td[7]')).text());
console.log("6: "+scrapeArray[6]);
}).then(function(){
    numberOf++;
    driverLoop();
}).then(null, function(err){
    console.log("IDs Complete!");

});

I know this is an old question but, I had the same problem (except using webdriver.io) and the solution was that the [Object object] is actually a Promise object (rather than the String I was expecting -- I was looking at the wrong version of the API). ...getText().then((text)=>{ console.log(text);}); should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM