使用 Python 和 Selenium 处理随机的 ForeSee 弹出窗口 [英] Handle random ForeSee popup using Python and Selenium

查看:26
本文介绍了使用 Python 和 Selenium 处理随机的 ForeSee 弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码新手,我尝试使用 Selenium 和 Python 来点击网站并填充购物车.除了随机的 ForeSee 调查弹出窗口外,我的一切都运行良好.当它出现时(它并不总是出现在同一个位置),我的代码在那时停止工作.

I'm new to coding and trying to use Selenium with Python to click through a website and fill a shopping cart. I've got things working well except for the random ForeSee survey popup. When it appears (and it doesn't always appear in the same location), my code stops working at that point.

我阅读了 ForeSee 文档,上面写着...当显示邀请时,fsr.r...cookie 被删除.此 cookie 可防止用户在 X 天内再次被邀请(默认为 90 天)."

I read the ForeSee documentation and it says "...when the invitation is displayed, the fsr.r...cookie is dropped. This cookie prevents a user from being invited again for X days (default 90)."

希望快速修复,我创建了一个单独的 Firefox 配置文件并浏览了该网站并获得了 ForeSee 弹出式邀请 - 手动使用该配置文件时不再弹出.但是我在使用 Selenium 时仍然会弹出.

Hoping for a quick fix, I created a separate Firefox profile and ran through the website and got the ForeSee pop up invitation--no more pop up when manually using that profile. But I still get the pop up when using Selenium.

我使用了这个代码:

fp = webdriver.FirefoxProfile('C:path	oprofile')
browser = webdriver.Firefox(firefox_profile=fp)

我让 cookie 工作了.我使用的是本地文件夹而不是 C:path oprofile 中的漫游文件夹.使用漫游文件夹解决了这个问题.

我的问题编辑删除了关于 cookie 不起作用的部分:

有人可以建议代码来永久处理随机出现在随机页面上的 ForeSee 弹出窗口吗?

Can someone suggest code to permanently handle the ForeSee pop up that appears randomly and on random pages?

推荐答案

我正在使用 Protractor 和 JS,所以我不能给你实际的代码来处理这个问题,但我可以告诉你如何处理这个.

I'm using using Protractor with JS, so I can't give you actual code to handle the issue, but I can give you an idea how to approach this.

在浏览器控制台中执行以下脚本时 -

When following script is executed in the browser's console -

window.FSR.setFSRVisibility(true);

它使 ForeSee 弹出窗口出现在其余 HTML 元素之后.并且不再影响 UI 测试

it makes ForeSee popup appear behind the rest of HTML elements. And doesn't affect UI tests anymore

所以我的量角器脚本看起来像这样

So my protractor script will look like so

await browser.executeScript(
  `window.FSR.setFSRVisibility(true);`
);


理论

因此,ForeSee 是可以与任何网络应用程序集成的服务之一,它将通过在网站范围内执行代码,从其 API 中提取 js 代码并更改应用程序的 HTML.此类公司的另一个例子是 walkme

显然,在现代世界中,如果这些人可以覆盖网页,他们应该有一个配置以使其成为可选(至少对于较低的环境)并且他们确实做到了.我提到的解决方案来自 this page.但是假设他们没有这样的选择,人们可以联系他们并询问如何解决他们的弹出窗口.即使他们没有这样的选项,他们也会很乐意将其视为一项改进功能.

Obviously in modern world, if these guys can overlay a webpage, they should have a configuration to make it optional (at least for lower environments) and they actually do. What I mentioned as a solution came from this page. But assuming they didn't have such option, one could reach out their support and ask how to workaround their popups. Even if they didn't have such option they would gladly consider it as a feature for improvement.

这篇关于使用 Python 和 Selenium 处理随机的 ForeSee 弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆