javascript - Puppeteer 不会点击元素

标签 javascript cucumber cucumberjs puppeteer

尝试让 Puppeteer 浏览我的登录页面,这会将自动化测试带到我网站的主页。一切正常,直到到达“waitFor('#idSIButton9');”。 Puppeteer 成功输入密码和用户名,但似乎无法选择提交按钮(#idSIButton9)。知道这里可能出了什么问题吗?如果你们需要更多信息,请告诉我。 谢谢:)

const puppeteer = require('puppeteer');
    const { defineSupportCode } = require('cucumber')

    defineSupportCode(({ Before, Given, When, Then }) => {
        Before({ timeout: 60 * 1000 }, async function testCase() {

            this.browser = await puppeteer.launch({ headless: false });

            this.page = await this.browser.newPage();

            await this.page.setViewport({width: 1024, height: 768});

            await this.page.goto('http://localhost:3000', {waitUntil: 'networkidle2'});

            await this.page.screenshot({ path: 'test_artifacts/img/load.png', fullPage: true });

            await this.page.waitFor('button');

            await this.page.click('button');

            await this.page.waitFor('#i0116');

            await this.page.type('#i0116', 'username');

            await this.page.waitFor('#i0118');

            await this.page.type('#i0118', 'password');

            await this.page.waitFor('#idSIButton9');

            await this.page.click('#idSIButton9');

        })

最佳答案

我似乎发现,如上面的答案

page.waitForNavigation('load') 

在点击触发导航的情况下效果很好。

关于javascript - Puppeteer 不会点击元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48262760/

相关文章:

javascript - 将页面的 HTML 片段复制到剪贴板

javascript - 创建 "fake AI"聊天程序

javascript - 在 Angularjs 中使用多个指令

javascript - 如何让我的获取错误显示 http 状态代码?

ruby - 用于存储正确答案的 cucumber 数据表的步骤定义

ruby - Cucumber : I want to send report on email after my all the scenario get executed, 有没有像 'AfterAll' 这样的方法可以在 hooks.rb 中使用

java - cucumber .runtime.CucumberException : Couldn't load plugin class: json-pretty with Cucumber Selenium and Java

automated-tests - 在 cucumber/testCafe 中实现 requestHooks

testing - Cucumber - Javascript 在其他步骤定义之前调用登录步骤定义

javascript - 使用 expect 验证元素的数量