什么是对象Promise和对象object ?硒+ JavaScript



我想获得一个团队名称等…我使用selenium和Javascript。我想要的是网页和今天的球队名称。

但是console.log显示

[NBA][object Promise]([object Object]) -vs- [object Object]([object Object])    [object Object]    [object Object

什么是对象Promise和对象object ?我的代码是

let chrome = require('selenium-webdriver/chrome');
let By = webdriver.By;
let Builder = webdriver.Builder;
let until = webdriver.until;
let Key = webdriver.Key;
let map = webdriver.promise.map;
(async () => {
try {
var driver = await new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeService(new chrome.ServiceBuilder(
"C:\ScoreAndOdds\JS\chromedriver.exe")).build();
await driver.get("https://www.scoresandodds.com/nba");
//await driver.get("https://www.scoresandodds.com/mlb");
await driver.sleep(2500);
var elements = await driver.findElements(By.xpath("//*[@class='event-card']"));
var vals = await map(elements, element => element.getAttribute('id')).then();
var id =[];
//vals.forEach(val => console.log(val));
vals.forEach(val => id.push(val));
console.log("----");
console.log(id);
//console.log(id[1]);

driver.findElement(By.xpath('/html/body/footer/div[3]/div/div/a[2]')).click();
await driver.sleep(2500);
const home = driver.findElement(By.xpath('//*[@id="nba.18032"]/table/tbody/tr[1]/td[1]/div/span[2]/span[1]/span'));
const homeN = driver.findElement(By.xpath('//*[@id="nba.18032"]/table/tbody/tr[1]/td[1]/div/span[2]/span[2]/a/span'));
const away = driver.findElement(By.xpath('//*[@id="nba.18032"]/table/tbody/tr[2]/td[1]/div/span[2]/span[1]/span'));
const awayN = driver.findElement(By.xpath('//*[@id="nba.18032"]/table/tbody/tr[2]/td[1]/div/span[2]/span[2]/a/span'));
const playtime = driver.findElement(By.xpath('//*[@id="nba.18032"]/table/thead/tr/th[1]/span[2]'));
const tv= driver.findElement(By.xpath('//*[@id="nba.18032"]/table/thead/tr/th[1]/span[2]'));
await driver.sleep(2500);
console.log("[NBA]" + home + "(" + homeN + ")" +" -vs- " + away + "(" + awayN + ")" + "    " + playtime + "    " + tv + "nnn");

谁能教我怎么得到球队的名字?

我得到了这个代码。

let home = await driver.findElement(By.xpath('//*[@id="nba.18035"]/table/tbody/tr[1]/td[1]/div/span[2]/span[1]/span')).getText();
console.log(home);

相关内容

  • 没有找到相关文章