Pry*_*me8 4 javascript selenium webdriver gettext node.js
我有一个硒脚本,应该从包含所需值的单元格后面的表列中获取文本。
我的脚本正在运行,但由于某种原因,当我运行 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!");
});
Run Code Online (Sandbox Code Playgroud)
我知道这是一个老问题,但是,我遇到了同样的问题(除了使用 webdriver.io),解决方案是 [Object object] 实际上是一个 Promise 对象(而不是我期望的 String - 我正在查看API 版本错误)。...getText().then((text)=>{ console.log(text);});应该管用。
| 归档时间: |
|
| 查看次数: |
1916 次 |
| 最近记录: |