web-scraping - 如何在单页应用程序中单击其后面的元素之前等待上述对话框消失
问题描述
我必须在对话框中输入邮政编码。单击按钮输入邮政编码后,我尝试等待提示关闭,然后再单击其他按钮,但在提示关闭时无法正确等待单击下一个按钮。 关闭前的对话框示例
原因包括以下几点:
我不能使用 waitForSelector(" ", {visible:true}) 因为选择器已经在初始对话后面可见。
我不能使用 waitForNavigation 因为关闭初始选项卡不会更改页面。
我试图避免在页面加载之前手动等待一段时间。
我也尝试等待上述对话框变为空,但在下一个按钮实际可点击之前它发生得太快了。
//await self.page.waitForFunction('document.querySelector("div.shopping-context-container") == null');
我想知道当上面的对话框试图关闭时,是否有办法等待下一个按钮实际可点击。
await enterInput.click(); // Submit zip code
await self.page.waitForSelector("button#nav-shopping-selector-postalcode", {
visible: true, // This automatically is true because the selector is already visible behind the prompt
});
let zipcodeButton = await self.page.$(
"button#nav-shopping-selector-postalcode",
{
visible: true,
}
);
await zipcodeButton.click(); // Clicks next button before page is properly loaded
await self.page.waitForSelector("input#shopping-selector-postal-code", {
visible: true,
});
// Breaks here because the second button wasn't clicked and so there is no node for this selector
await self.page.type("input#shopping-selector-postal-code", zip);
解决方案
这似乎是正确的想法:
await self.page.waitForFunction(() => !document.querySelector("div.shopping-context-container"))
但我不知道那个 div 是被删除还是被隐藏了。
推荐阅读
- python - 当保持客户端套接字打开以发送多个消息时,为什么当消息延迟很大时程序会出错?
- polymer - 聚合物测试失败,“铬未能最大化”
- javascript - 如何正确修复节点中的渲染 ejs
- angular - 使用 Ng 模型选择下拉菜单不反映 Internet Explorer 11 中的更改
- php - 如何通过 Laravel 为 S3 实现 Amazon V4 签名?
- linq - MVC 多对多仅在代码中首先获取具有某种类型的实体
- php - laravel 多表单路由
- r - 当需要的多个条件在另一个表中时执行求和?
- selenium - 如果多个编辑按钮具有相同的 HTML 编码,我将如何单击 Selenium 中的按钮
- typo3 - TYPO3 9.5.3 - 显示多次尝试访问不存在路由的日志错误