简体   繁体   English

使用Selenium切换到Firefox浏览器

[英]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.

相关问题 使用硒python的前景Firefox浏览器(Mac OSX) - Foreground Firefox browser using selenium python (Mac OSX) 在 Mac 上使用 Python 和 Firefox 的 selenium webdriver 问题 - Problems with selenium webdriver using Python and Firefox on a Mac 如何使用Selenium 3.4.3启动firefox(不是firefox-bin), - How to launch firefox (not firefox-bin) using Selenium 3.4.3, 在Mac OS X上使用Robot Framework在Firefox中运行Selenium Test会导致Selenium Server /空白浏览器窗口挂起 - Running Selenium Test in Firefox with Robot Framework on Mac OS X Results in Hanging Selenium Server / Blank Browser Window 在Mac上使用Selenium WebDriver在Firefox中打开新标签页 - Open new tab in Firefox using Selenium WebDriver on Mac 使用Firefox 31.0在Mac OS X上上传硒文件 - selenium file upload on mac osx using firefox 31.0 在浏览器中切换IP - Switch IP's in browser 无法使用 Selenium 和 Java 在 Mac OSX 中启动 Safari 12 浏览器 - Unable to launch Safari 12 browser in Mac OSX using Selenium and Java 有些点击不能使用selenium独立服务器在Safari浏览器中工作 - Some click dont work in Safari browser using selenium standalone server Safari 浏览器:无法使用 Selenium 在 Safari 浏览器上单击文件类型元素 - Safari Browser: Not able to click file type element on safari browser using Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM