我在Selenium WebDriver上运行自动化测试,作为来自IntellijIdea的JUnit测试。当浏览器打开并在其中执行某些操作时,即使我使用Tab键切换到其他窗口,它也始终会自动显示在最前面。这不是很方便。有些测试会运行几分钟,我希望能够在运行时处理一些其他任务。或者,如果我想运行整个套件,我不能只是坐着看30分钟。
在我从Windows操作系统切换到Linux Mint之后,我开始遇到这个问题。在Windows上的浏览器仍然在后台,并没有打扰我。有没有办法在Linux Mint OS上配置这样的行为?
我已经尝试在单独的LinuxMint工作区中运行browser/IntelliJ Idea,但没有帮助。在另一个工作区中完成某些活动后,浏览器窗口会立即弹出。我还在LinuxMint的windows行为设置中设置了这个配置:

发布于 2017-04-21 16:22:39
从本周开始(chrome 57或更高版本),可以运行chrome in headless mode。为此,只需传递--headless标志即可。
要通过Selenium webdriver将此标志传递给chrome,您可以使用以下代码:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
ChromeDriver chromeDriver = new ChromeDriver(options);不过,我不确定这是否完全解决了焦点问题。在我的例子中,仍然有一个chrome窗口偷走了焦点,但我认为这是一个很大的改进,因为窗口不会在我正在做的事情之前弹出。
我认为这绝对值得一试。我会继续关注焦点问题,如果我发现了什么,就会更新。
发布于 2016-08-22 22:21:22
Selenium没有内置的最小化浏览器的方法,但是您可以使用以下命令使浏览器看不见:
driver.manage().window().setPosition(new Point(-2000, 0));虽然这种“黑客攻击”会将浏览器窗口移出视线,但当驱动程序初始化时,浏览器将短暂可见。
发布于 2016-08-23 02:25:19
尝试使用RemoteDriver,它将使用最小化的浏览器执行代码。提供本地主机ip作为主机地址。代码应该是这样的。
try {
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList(
"--start-maximized", "--disable-popup-blocking"));
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/BrowserDrivers/chromedriver.exe");
// Code to faster execution on Chrome
ChromeOptions chromOpt = new ChromeOptions();
chromOpt.addArguments("Proxy","null");
capabilities.setCapability(ChromeOptions.CAPABILITY,chromOpt );
driver = new RemoteWebDriver(new URL("http://127.0.0.1:5555/wd/hub"), capabilities);*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}https://stackoverflow.com/questions/39078220
复制相似问题