Node.js Selenium等待并单击using nodejs

Node.js Selenium等待并单击using nodejs,node.js,selenium,Node.js,Selenium,我正在尝试登录fifa ultimate team。。。但我不知道为什么如果我尝试使用等待,单击操作没有任何效果。。。 基本上我的网址是 我需要点击的按钮是登录 有什么想法吗 require('chromedriver'); const webdriver = require('selenium-webdriver'); var until = webdriver.until; var By = webdriver.By; async function myMain(){ let

我正在尝试登录fifa ultimate team。。。但我不知道为什么如果我尝试使用等待,单击操作没有任何效果。。。 基本上我的网址是 我需要点击的按钮是登录 有什么想法吗

require('chromedriver');
const webdriver = require('selenium-webdriver');

var until = webdriver.until;
var By = webdriver.By;

async function myMain(){

    let driver = new webdriver.Builder().forBrowser('chrome').build();
    await driver.get('https://www.easports.com/fifa/ultimate-team/web-app/');
    await driver.wait(until.elementLocated(By.className('btn-standard call-to-action')), 15000);
    await driver.findElement(By.className('btn-standard call-to-action')).click();
}

myMain();

您的选择器可能不太正确。试试这个:

  await driver.wait(until.elementLocated(By.xpath("//button[text()='Login']")),15000);
  let loginButton = driver.findElement(By.xpath("//button[text()='Login']"));

  await driver.wait(until.elementIsEnabled(loginButton ,15000));

  await driver.findElement(By.xpath("//button[text()='Login']")).click();

谢谢你的回答。我试图得到这样一条消息:UnhandledPromisejectionWarning:NoSuchElementError:没有这样的元素:找不到元素:{“方法”:“xpath”,“选择器”:“//button[text()='Login']”,因为加载元素需要几秒钟的时间。。。您在浏览器上试过了吗?很抱歉,我的解决方案没有考虑到最初的长加载时间。我已经相应地更新了我的答案。没有问题。。。我在wait driver.wait行中得到错误“TypeError:element.isDisplayed不是函数”。。。有什么想法吗?
element.isDisplayed
意味着接受一个现有的WebElement,而
elementVisible
则接受By作为参数。更新了我的示例,改为使用
elementVisible
,并添加了额外的等待
elementisabled
。非常感谢!!!它工作!!!您只需在loginButton之后添加一个)15000