使用 selenium Java (Mac OSX) 将 Firefox 浏览器置于前端 [英] Bring the Firefox Browser to Front using selenium Java (Mac OSX)

查看:39
本文介绍了使用 selenium Java (Mac OSX) 将 Firefox 浏览器置于前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用三个 firefox 驱动程序实例进行自动化.我需要将当前活动的 firefox 浏览器放在前面,因为我正在使用一些 robo 类进行一些操作.我曾在 mac 中为谷歌浏览器尝试过 java 脚本警报(相同的操作)并且它工作正常.在 Windows 中使用 user32 lib.在 firefox mac 的情况下,它在后台显示警报,但网页没有出现在前面.

I am using three instances of fire fox driver for automation.I need to bring current active firefox browser into front, Because I am using some robo classes for some opertation. I had tried java script alert for google chrome in mac ( same operation) and its worked fine. In windows used user32 lib. In the case of firefox mac its showing the alert in background but the web page is not come into front.

((JavascriptExecutor)this.webDriver).executeScript("alert('Test')");
this.webDriver.switchTo().alert().accept();

以上代码我在 Mac 中用于 chrome.相同的代码正在运行并显示 Firefox 警报,但窗口没有出现在前面.

The above code I used for chrome in Mac. Same code is working and showing alert for firefox but the window is not coming to front.

请建议是否有其他方法可以在 Firefox 中执行相同操作.

Please suggest if there any other method for doing the same in firefox.

推荐答案

首先将窗口句柄存储在一个变量中,然后使用它返回到窗口.

Store the window handle first in a variable, and then use it to go back to the window later on.

//Store the current window handle
String currentWindowHandle = this.webDriver.getWindowHandle();

//run your javascript and alert code
((JavascriptExecutor)this.webDriver).executeScript("alert('Test')"); 
this.webDriver.switchTo().alert().accept();

//Switch back to to the window using the handle saved earlier
this.webDriver.switchTo().window(currentWindowHandle);

此外,您可以尝试在切换到窗口后最大化窗口,这也应该激活它.

Additionally, you can try to maximise the window after switching to it, which should also activate it.

this.webDriver.manage().window().maximize();

这篇关于使用 selenium Java (Mac OSX) 将 Firefox 浏览器置于前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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