【发布时间】:2014-09-08 19:57:00
【问题描述】:
我有一个 selenium 脚本,它应该从包含所需值的单元格之后的表格列中获取文本。
我的脚本可以工作,但是由于某种原因,当我运行 getText() 并检查返回的值时,我在 node.js 控制台中得到 [Object Object] ...我很困惑,我试图将其解析为一个字符串,我在变量上调用了 getText() ,这将是元素和其他几种方法,但无济于事......
这是我的脚本的相关部分:
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!");
});
【问题讨论】:
-
我在你的脚本中看到,你使用了 text() 而不是 getText()。你是故意用的吗?
-
我都试过了,不幸的是下班了。
-
能否请您发布您的完整脚本?
标签: javascript node.js selenium webdriver gettext