[英]Switch to Firefox browser using Selenium
Firefox browser only launches on Dock on my Mac but active screen shown is still Eclipse. Firefox浏览器仅在我的Mac上的Dock上启动,但显示的活动屏幕仍然是Eclipse。
How can the focus be shifted to Browser? 如何将焦点转移到浏览器?
public class FirefoxFirst {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","/Users/varunnadimpalli/Downloads/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://google.com");
selenium :3.3.1 硒:3.3.1
Mac:`10.12.1 苹果:`10.12.1
Strange why it wouldn't swap focus to firefox, if it is not in focus but still open try 奇怪为什么它不会将焦点交换到firefox,如果它不是焦点但仍然打开尝试
((JavascriptExecutor) webDriver).executeScript("window.focus();");
If it is minimized you can try going through the windows handles 如果它被最小化,你可以尝试通过窗口句柄
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
See if that is able to bring the firefox window up. 看看是否能够启动firefox窗口。
Not sure whether this works. 不确定这是否有效。 Try maximizing the browser,
尝试最大化浏览器,
driver.manage().window().maximize();
Also, don't forget to add implicit wait after initiating the browser. 此外,不要忘记在启动浏览器后添加隐式等待。
Note - I don't have enough points to comment this. 注意 - 我没有足够的观点对此发表评论。 else i have commented instead of writing this as answer.
否则我评论而不是写这个作为答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.