Puppeteer不会点击元素

时间:2018-01-15 12:10:30

标签: 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');

        })

2 个答案:

答案 0 :(得分:1)

似乎相当明显但在点击之前等待使用数值:

await this.page.waitFor(2000);

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

await this.page.waitForNavigation();

答案 1 :(得分:1)

我似乎发现,正如上面的回答

page.waitForNavigation('load') 

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

相关问题