有没有办法调试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) 如何处理弹出窗口并访问弹出窗口对其进行一些操作.
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) 我正在使用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) 运行新页面时,必须使用以下setViewport函数指定视口的大小:
await page.setViewport({
width: 1920,
height: 1080
})
Run Code Online (Sandbox Code Playgroud)
我想使用最大视口。
如何根据窗口大小调整视口的大小?
javascript viewport node.js google-chrome-devtools puppeteer
是否可以将浏览器连接到 puppeteer 而无需在 puppeteer 中实例化它?例如,像普通用户一样运行一个 Chromium 实例,然后在代码中将它连接到一个 puppeteer 实例?
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.
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 .
Anyone …
我想在不使用 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) 在 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) 我想在使用 puppeteer 节点模块渲染 PDF 时从本地文件加载字体。
使用网络字体对我有用,但这不满足要求。
我的环境:
这是我到目前为止尝试过的代码:使用@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) 我创建了一个使用 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
但问题是,我无权在共享托管平台上这样做。
有什么解决方法可以解决这个问题吗?或者有没有办法将库嵌入为静态库而不是共享库?
先感谢您!
puppeteer ×10
node.js ×8
javascript ×5
css ×1
e2e-testing ×1
fonts ×1
jestjs ×1
linux ×1
viewport ×1
web-testing ×1
webtest ×1