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

查看:236
本文介绍了使用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\to\profile')
browser = webdriver.Firefox(firefox_profile=fp)

我使cookie正常工作了.我使用的是本地文件夹,而不是C:\ path \ to \ profile中的漫游文件夹.使用漫游文件夹解决了该问题.

我的问题已编辑以删除有关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是可以与任何Web应用程序集成的服务之一,并且将通过在网站范围内执行代码来从其API中提取js代码并更改应用程序的HTML.这种公司的另一个例子是 walkme


Theory

So ForeSee is one of those services that can be integrated with any web app, and will be pulling js code from their API and changing HTML of your app, by executing the code on the scope of the website. Another example of such company is walkme

显然,在现代世界中,如果这些人可以覆盖网页,则他们应该具有使其可选的配置(至少对于较低的环境而言),而实际上他们确实可以这样做.我提到的解决方案来自此页面.但是,假设他们没有这样的选择,则可以向他们伸出援手,并询问如何解决弹出窗口.即使他们没有这样的选择,他们也会很乐意将其视为改进的功能.

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天全站免登陆