将Firefox浏览器使用selenium Java(Mac OSX) [英] Bring the Firefox Browser to Front using selenium Java (Mac OSX)
问题描述
((JavascriptExecutor)this.webDriver).executeScript(alert('Test'));
this.webDriver.switchTo()。alert()。accept();
以上代码是用于Mac中的chrome。相同的代码工作,并显示Firefox的警报,但窗口不会到前面。
请建议是否有任何其他方法在firefox中做同样的。
将窗口句柄首先存储在一个变量中,然后再用它返回窗口。
$ b
//存储当前窗口句柄
字符串currentWindowHandle = this.webDriver.getWindowHandle();
//运行你的javascript和提示代码
((JavascriptExecutor)this.webDriver).executeScript(alert('Test'));
this.webDriver.switchTo()。alert()。accept();
//使用之前保存的句柄切换回窗口
this.webDriver.switchTo()。window(currentWindowHandle);
另外,您可以尝试在切换到最大化窗口后使窗口最大化。 / p>
this.webDriver.manage()。window()。
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();
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.
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();
这篇关于将Firefox浏览器使用selenium Java(Mac OSX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!