使用Selenium自动执行测试时,如何处理调试器中暂停的叠加层 [英] How to deal with the overlay Paused in debugger while automated test execution using Selenium

查看:398
本文介绍了使用Selenium自动执行测试时,如何处理调试器中暂停的叠加层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试访问此我无法通过检查器检查任何元素,因为UI上有一个叠加层以及消息 在调试器中已暂停

>



赞成并接受了此讨论的答案谈到了手动步骤



所有解决方案似乎都指向手动过程。但是在我看来,这个问题似乎是 Selenium 无法 getPageSource()



代码试用:

  System.setProperty( webdriver.chrome.driver, C:\\Utility\​​\\BrowserDrivers\\chromedriver.exe); 
ChromeOptions options = new ChromeOptions();
options.addArguments( start-maximized);
options.addArguments( disable-infobars);
options.addArguments(-disable-extensions);
WebDriver驱动程序=新的C​​hromeDriver(选项);
driver.get( http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm);

输出:Chrome打开,但不导航到URL。



所以我的问题是:




  • 在这种情况下可以在调试器中暂停 发生错误吗?

  • 前端开发是否出错?

  • 如何在 Automated通过测试


解决方案


  • 在哪种情况下会发生在调试器中暂停错误?



    任何时候您都在打开开发工具的情况下访问此页面。 debugger; 行将暂停javascript执行,但是如果关闭开发工具,浏览器将忽略它。


  • 前端开发是否出错?



    在这种情况下,不-他们有意将您拒之门外。此功能的目的是暂停执行,然后在恢复时间超过100毫秒时将您的浏览器重定向到其他页面。我推测这是为了干扰诸如硒之类的自动爬虫,因为普通用户不会受到影响,而人类开发人员也可以入侵它。


  • 如何通过硒自动测试期间绕过此错误?




我如果可以的话,第一个建议是尝试无头运行Selenium。如果不是,请使用热键恢复执行(F8)。。您可以使用任何喜欢的方法生成按键。使用java.awt软件包,它将看起来像这样:

  Robot robot = null; 
试试
{
robot = new Robot();
}
catch(Exception e)
{
//处理失败
}
robot.keyPress(KeyEvent.VK_F8);

请记住,您必须在100ms内触发此操作,因此请使用您喜欢的任何逻辑来检测该块并快速回应。如果您只想要快速又肮脏的东西,我可以让它每隔50毫秒按F8键一次,直到您确定页面已加载为止。



编辑:在进一步调查中,此页面对开发工具处于打开状态的任何人都极为混乱和敌视。触发 debugger; 的函数只有一个,而只要您在页面上,它们就会在计时器上反复被调用。除非您想在整个会话期间继续向F8发送垃圾邮件,否则,无头奔跑似乎是最好的选择。


Everytime I try to access this I am unable to inspect any of the elements through the Inspector as the UI is having an overlay along with a message Paused in debugger.

The upvoted and accepted answer of this discussion says to check the Source tab, check under the Event Listener Breakpoints panel if you've set any breakpoints under 'Mouse'. I have cross checked that none of the Sources -> EventListenerBreakpoint are set.

The upvoted and accepted answer of this discussion says to check if the little octagonal stop/pause sign (at lower left of Chrome "Sources") is colored (blue or purple). I am not sure why do I need to do that additionally for selected websites.

Snapshot:

The upvoted and accepted answer of this discussion speaks about the Manual Steps.

All the solutions seem to point towards the manual process. But this issue seems to me the root cause behind Selenium being unable to getPageSource().

Code trials:

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm");

Output: Chrome opens but doesn't navigates to the url.

So my questions are:

  • In which case can Paused in debugger error occurs?
  • Is it an error from the frontend development?
  • How can I bypass this error during the Automated Tests through Selenium?

解决方案

  • In which cases can the Paused in debugger error occur?

    Anytime you are accessing this page with the dev tools open. The debugger; line will pause javascript execution, but browsers will ignore it if the dev tools are closed.

  • Is it an error from the frontend development?

    In this case, no--they're deliberately trying to keep you out. The purpose of this function is to pause execution and then redirect your browser to a different page if it takes longer than 100ms to resume. I would speculate that this is designed to interfere with automated crawlers like selenium, because a regular user wouldn't be affected and a human developer can just hack around it.

  • How can I bypass this error during the Automated Tests through Selenium?

My first recommendation would be to try running Selenium headlessly, if that's an option. If not, use the hotkey to resume execution (F8). You can use whatever method you like for generating a keypress; with the java.awt package it will look something like this:

Robot robot = null;
try
{
   robot = new Robot();
}
catch(Exception e)
{
   //handle failure
}
robot.keyPress(KeyEvent.VK_F8);

Remember that you have to trigger this within 100ms, so use whatever logic you like to detect the block and respond quickly. If you just want something quick and dirty, I would just make it spam F8 keypresses every 50ms for a period of time until you're certain the page has loaded.

EDIT: On further investigation, this page is extremely messy and hostile to anyone with the dev tools open. There is not one but several functions that trigger debugger;and they get called repeatedly on a timer for as long as you're on the page. Running headlessly seems like the best choice, unless you want to continue spamming F8 for the entire session.

这篇关于使用Selenium自动执行测试时,如何处理调试器中暂停的叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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