[英]Switch to Firefox browser using Selenium
Firefox浏览器仅在我的Mac上的Dock上启动,但显示的活动屏幕仍然是Eclipse。
如何将焦点转移到浏览器?
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");
硒:3.3.1
苹果:`10.12.1
奇怪为什么它不会将焦点交换到firefox,如果它不是焦点但仍然打开尝试
((JavascriptExecutor) webDriver).executeScript("window.focus();");
如果它被最小化,你可以尝试通过窗口句柄
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
看看是否能够启动firefox窗口。
不确定这是否有效。 尝试最大化浏览器,
driver.manage().window().maximize();
此外,不要忘记在启动浏览器后添加隐式等待。
注意 - 我没有足够的观点对此发表评论。 否则我评论而不是写这个作为答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.