使用操纵符时确认或关闭对话框

问题描述 投票:0回答:1

我正在尝试关闭Puppeteer中的对话框。我尝试转换原始的Puppeteer指令,但是没有用。

我正在爬网的网站从body onload中引发警报。

这是我到目前为止没有运气的东西。

$js_function = JsFunction::createWithAsync()
     ->body('async dialog => {
     await dialog.dismiss();
}');

$this->page->on('dialog', $js_function);

$this->page->goto($this->url);

原始的伪造者文档:https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-dialog

php puppeteer
1个回答
0
投票

您几乎做对了所有事情,但是有一个小错误。

这里是正确的代码:

$js_function = JsFunction::createWithAsync()
    ->parameters(['dialog'])
    ->body('await dialog.dismiss()');

$this->page->on('dialog', $js_function);

$this->page->goto($this->url);
© www.soinside.com 2019 - 2024. All rights reserved.