简体   繁体   English

处理在Java / Selenium中停止处理的浏览器弹出窗口

[英]Handling browser pop-ups that stop processing in Java/Selenium

Environment : Selenium testing in Java against Chrome 环境 :针对Chrome的Java硒测试

Scenario : in the GUI of my application I have a button that causes a form full of data to be submitted to an external service, whereupon the user is re-directed to the external service landing page. 场景 :在我的应用程序的GUI中,我有一个按钮,该按钮使充满数据的表单提交到外部服务,随后用户被重定向到外部服务登录页面。

Because my application is inside my corporate firewall, a username/password has to be supplied for consumption by the external service, but the application is not aware of this, so doesn't provide it (it would work normally in production, but the test environment is a special case). 由于我的应用程序位于公司防火墙内部,因此必须提供用户名/密码以供外部服务使用,但该应用程序不知道这一点,因此不提供它(它可以在生产环境中正常工作,但需要经过测试环境是一种特殊情况)。 Therefore, a pop-up appears, and during manual testing the tester supplies a username and password manually and then submits the dialog. 因此,会出现一个弹出窗口,并且在手动测试期间,测试人员手动提供用户名和密码,然后提交对话框。 This is not a JavaScript dialog - I assume it's an actual modal Windows dialog, so it effectively halts processing and selenium just waits around till it's gone. 这不是JavaScript对话框-我认为它是一个实际的模态Windows对话框,因此它有效地暂停了处理,硒只是在等待直到消失。

Problem : I am trying to automate this process, and cannot get passed the dialog. 问题 :我正在尝试使此过程自动化,并且无法通过对话框。 Because the dialog prevents java/selenium from processing, I cannot implement code to handle the dialog, such as integrating AutoIt or using Robot , because program flow never gets to that code after the button is pressed. 因为对话框阻止Java / Selenium的处理,所以我无法实现处理对话框的代码,例如集成AutoIt或使用Robot,因为按下按钮后程序流就永远无法到达该代码。 Usually, I'd install an independent version of AutoIt to run on my machine in the background and catch the pop-up (not ideal, but it works), but due to very tight restrictions in the corporate domain policy this isn't possible in the short-term. 通常,我会安装一个独立版本的AutoIt在后台在我的计算机上运行并捕获弹出窗口(不理想,但可以运行),但是由于公司域策略的严格限制,这是不可能的在短期内。 I suspect they have a white-list for executables, so it may be tricky getting any third-party tool to work. 我怀疑他们有可执行文件的白名单,因此让任何第三方工具正常工作可能很棘手。

Can anybody think of a way around this? 有人可以考虑解决这个问题的方法吗?

  • Can't use Alerts, as these are not JavaScript dialogs 无法使用警报,因为这些不是JavaScript对话框
  • I have to be able to enter the username, password and submit the dialog 我必须能够输入用户名,密码并提交对话框
  • Can't use integrated capabilities like AutoIt or Robot 不能使用AutoIt或Robot之类的集成功能
  • Can't use an independent tool like AutoIt due to domain policy 由于域政策,无法使用像AutoIt这样的独立工具

I suspect it's not possible, but worth checking if any bright spark has any ideas. 我怀疑这是不可能的,但值得检查是否有任何火花有任何想法。

It's not supported in WebDriver so it can't be done using plain Selenium. WebDriver不支持此功能,因此无法使用普通的Selenium完成。

There is an issue open in the WebDriver project to support handling basic auth prompts: WebDriver项目中存在一个开放的问题,以支持处理基本身份验证提示:

https://github.com/w3c/webdriver/issues/385 https://github.com/w3c/webdriver/issues/385

https://github.com/SeleniumHQ/selenium/issues/453 https://github.com/SeleniumHQ/selenium/issues/453

Alas, the issue is open and nothing is implemented yet. las,这个问题尚未解决。

If you can't use AutoIt from another process because that process has to be in a certain whitelist, then you can probably use it from another thread using autoitx4java . 如果您不能从另一个进程使用AutoIt,因为该进程必须位于某个白名单中,那么您可以使用autoitx4java从另一个线程使用 If you can detect the dialog itself then you should certainly do it, but AFAIK the dialogs of Chrome are transparent to AutoIt (any other technologies based on Windows UIAutomation). 如果您可以检测到对话框本身,那么您当然应该这样做,但是AFAIK Chrome的对话框对AutoIt(基于Windows UIAutomation的其他任何技术)都是透明的。 In this case, just spawn the thread before pressing the button, make this thread sleep for 1 second or so (in the first statement of the thread method), and then "blindly" type the user name, Tab key, the password, and Enter. 在这种情况下,只需在按下按钮之前生成线程,使该线程休眠1秒钟左右(在thread方法的第一条语句中),然后“盲目”键入用户名,Tab键,密码和输入。 It's not very element, but I believe it should work. 它不是非常重要的元素,但我认为它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Selenium Webdriver(3.x)处理自定义弹出窗口(不是默认窗口) - Handling custom pop-ups (not the default windows one) through selenium webdriver (3.x) 有什么方法可以更改弹出窗口的默认阻止设置并重定向以允许使用 selenium java 在 chrome 中使用? - Is there any way to change default block setting of pop-ups and redirect to allow in chrome using selenium java? 如何使用Selenium Firefox WebDriver处理多个弹出窗口 - How to handle multiple pop-ups with selenium firefox webdriver 在Java弹出窗口中重复使用JTextField - Re-using JTextField in Java pop-ups 我们可以自动化浏览器设置,例如在浏览器启动时禁用弹出窗口吗? - Can we automate browser settings, like disabling pop-ups whenever browser starts? 在eclipse插件中动态更改弹出窗口 - Changing pop-ups dynamically in eclipse plugin 是否可以使用 Java 中的 JOptionPane 同时显示多个弹出窗口? - Is it possible to have multiple pop-ups present at the same time using the JOptionPane in java? 处理应用程序中的常见弹出窗口Java WebDriver Testng - Handling common pop ups across the application java webdriver testng 无法使用 Robot 类处理 Windows 10 弹出窗口 - Unable to handle Windows 10 pop-ups using Robot class 如何阻止java警告弹出窗口一次又一次地出现 - How to stop java warning pop ups from appearing again and again
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM