标签: puppeteer

调试木偶操纵者

有没有办法调试puppeteer脚本?由于某种原因,其中一个按钮没有被点击.我已经尝试了所有不同的方式,实际上在另一个脚本中我点击它,但在这一个我没有.

await page.focus('#outer-container > nav > span.right > span.search-notification-wrapper > span > form > input[type="text"]');
await page.type("Some text");
await page.click('#outer-container > nav > span.right > span.search-notification-wrapper > span > form'); // I am clicking on the form because it did work in the other script
Run Code Online (Sandbox Code Playgroud)

javascript node.js puppeteer

11
推荐指数
3
解决办法
7305
查看次数

如何处理木偶戏中的弹出窗口

如何处理弹出窗口并访问弹出窗口对其进行一些操作.

const puppeteer = require('puppeteer');

async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await page.click(Launchpopup);
}
Run Code Online (Sandbox Code Playgroud)

node.js google-chrome-headless puppeteer

11
推荐指数
4
解决办法
9199
查看次数

如何在多个文件中运行Jest-Puppeteer测试

我正在使用jest-puppeteer来运行我的网络测试.如果我运行我在一个文件中定义的测试,一切都很完美.

describe('user', () => {

    jest.setTimeout(12000);

    beforeEach(async () => {
        await page.setViewport({width: 1200, height: 2000});
        await page.goTo('http://localhost:3000');
    });

    it('test 1', async () => {
        //my test steps
    });

    it('test 2', async () => {
        //my test steps
    });

});
Run Code Online (Sandbox Code Playgroud)

但是,如果我在自己的文件中运行每个测试,我会收到错误.

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined
Run Code Online (Sandbox Code Playgroud)

文件1

describe('user', () => {

    jest.setTimeout(12000);

    beforeEach(async () => {
        await page.setViewport({width: 1200, height: 2000});
        await page.goTo('http://localhost:3000');
    });

    it('test 1', async () => {
        //my test steps
    });

});
Run Code Online (Sandbox Code Playgroud)

文件2

describe('user', () …
Run Code Online (Sandbox Code Playgroud)

web-testing webtest jestjs e2e-testing puppeteer

11
推荐指数
1
解决办法
869
查看次数

如何在Puppeteer中设置最大视口?

运行新页面时,必须使用以下setViewport函数指定视口的大小:

await page.setViewport({
    width: 1920,
    height: 1080
})
Run Code Online (Sandbox Code Playgroud)

我想使用最大视口。

如何根据窗口大小调整视口的大小?

javascript viewport node.js google-chrome-devtools puppeteer

11
推荐指数
7
解决办法
1万
查看次数

在 Puppeteer 中连接浏览器

是否可以将浏览器连接到 puppeteer 而无需在 puppeteer 中实例化它?例如,像普通用户一样运行一个 Chromium 实例,然后在代码中将它连接到一个 puppeteer 实例?

javascript google-chrome webautomation node.js puppeteer

11
推荐指数
1
解决办法
8087
查看次数

使用“remote-debugging-port”标志调试 Chrome 实例

I\'m trying to follow the steps described under Basics: Using DevTools as protocol client on https://chromedevtools.github.io/devtools-protocol/. I launch two Chrome instances with google-chrome --remote-debugger-port=9222\n and google-chrome --user-data-dir=/home/whatever/Desktop/chrome/. After that, I navigate to http://127.0.0.1:9222/ but I get a "This site can\xe2\x80\x99t be reached" error page.

\n\n

If instead of this I launch Chrome with google-chrome --headless --remote-debugging-port=9222, when I navigate to http://127.0.0.1:9222/ I can see "Inspectable WebContents" and a link to a blank page .

\n\n

Anyone …

google-chrome google-chrome-devtools puppeteer

11
推荐指数
2
解决办法
2万
查看次数

如何使用 xPath 在 Puppeteer 中单击元素

我想在不使用 css 选择器的情况下单击一个元素。

await page.click()
Run Code Online (Sandbox Code Playgroud)

使用选择器来标识元素。


那么我该怎么做呢?

await page.click('/*[@id="toc"]/ul/li[1]/a')
Run Code Online (Sandbox Code Playgroud)

google-chrome node.js puppeteer

11
推荐指数
1
解决办法
1万
查看次数

如何检查 puppeteer 中是否存在选择器?

在 puppeteer 中,我如何检查例如 #idProductType 是否存在,如果不存在,将 producttype 设置为“”?我尝试了很多很多东西,但它不起作用。

            const urls = [myurls, ...]
            const productsList = [];
            for (let i = 0; i < urls.length; i++) {
                const url = urls[i];

                await Promise.all([
                    page.goto(url),
                    page.waitForNavigation({ waitUntil: 'networkidle0' }),
                ]);

                let products = await page.evaluate(() => {

              //here i want to test if #idProductType exists do : 
                    let producttype = document.querySelector('#idProductType').innerText;
              //else 
                    let producttype = "";
              //and same thing for other selectors

                    let productsubtype = document.querySelector('#idProductSubType').innerText;
                    let product = document.querySelector('#idProduct').innerText;
                    let description …
Run Code Online (Sandbox Code Playgroud)

javascript node.js puppeteer

11
推荐指数
5
解决办法
2万
查看次数

Puppeteer npm 如何从本地文件设置字体

我想在使用 puppeteer 节点模块渲染 PDF 时从本地文件加载字体。

使用网络字体对我有用,但这不满足要求。

我的环境:

  • 节点:v10.18.1,
  • 傀儡师:“傀儡师”:“^2.0.0”,
  • Chromium:Chromium 79.0.3945.88 Fedora 项目,
  • 操作系统:CentOS Linux 8.0.1905 版(核心)

这是我到目前为止尝试过的代码:使用@font-face 加载字体、更改 networkidle 的值、设置超时、设置用于字体更新的事件侦听器。事件我设置此回调以获取返回“Open Sans”但呈现的 PDF 文件不是 Open Sans 字体的字体属性。

const puppeteer = require('puppeteer');
const chromiumExecutablePath = '/bin/chromium-browser';

let document = `
    <html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>

            @font-face {
                font-family: "Open Sans";
                font-style: normal;
                font-weight: 400;
                src: local("Open Sans") url("/opt/www/webapp/resources/packed/OpenSans-Regular.eot");
                src: local("Open Sans") url("/opt/www/webapp/resources/packed/OpenSans-Regular.woof") format("woff"),
                     local("Open Sans") url("/opt/www/webapp/resources/packed/OpenSans-Regular.ttf") format("truetype");
            }

            html, body { …
Run Code Online (Sandbox Code Playgroud)

javascript css fonts node.js puppeteer

11
推荐指数
1
解决办法
2724
查看次数

加载 libatk-bridge-2.0.so.0 时出错

我创建了一个使用 Puppeteer 的 NodeJS 应用程序。在本地(Windows)上它工作得很好,但是当我想在共享托管平台(Linux 服务器)上部署该应用程序时,出现以下错误:

错误:无法启动浏览器进程!\n/var/app/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome:加载共享库时出错:libatk-bridge-2.0.so.0:无法打开共享对象文件:没有这样的文件或目录\n\n\n故障排除:https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n"

我发现的唯一解决方案是安装缺少的 libatk-bridge 依赖项

sudo apt-get install -y libgbm-dev

但问题是,我无权在共享托管平台上这样做。

有什么解决方法可以解决这个问题吗?或者有没有办法将库嵌入为静态库而不是共享库?

先感谢您!

linux shared-hosting shared-libraries node.js puppeteer

11
推荐指数
0
解决办法
1万
查看次数