简体   繁体   English

木偶将不会单击元素

[英]Puppeteer Won't Click on Element

Trying to get Puppeteer to navigate through my login page which will bring the automated test to the main page of my site. 试图让Puppeteer浏览我的登录页面,这会将自动测试带到我网站的主页。 It all works until it reaches 'waitFor('#idSIButton9');'. 直到到达“ waitFor('#idSIButton9');”为止,所有操作均有效。 Puppeteer successfully enters the password and username but can't seem to select the submit button(#idSIButton9). Puppeteer已成功输入密码和用户名,但似乎无法选择提交按钮(#idSIButton9)。 Any idea what might be going wrong here? 知道这里可能出什么问题吗? Let me know if you guys need more info. 让我知道你们是否需要更多信息。 Thanks :) 谢谢 :)

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');

        })

Seems fairly obvious but putting a wait before clicking works with a numeric value: 似乎很明显,但是在单击之前需要等待一段时间才能使用数字值:

await this.page.waitFor(2000);

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

await this.page.waitForNavigation();

I seems to find, as the above answer 我似乎发现,作为上述答案

page.waitForNavigation('load') 

Works well in cases where clicking triggers navigation. 在单击触发导航的情况下效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM