4

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!");

});
3
  • I see in your script, you used text() instead of getText(). You used it on purpose? Commented Jul 21, 2014 at 10:03
  • Ive tried both, and unfortunately nether work. Commented Jul 21, 2014 at 16:59
  • Could you please post your full script? Commented Jul 22, 2014 at 0:59

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

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.