【问题标题】:Maximize browser window in LeanFT在 LeanFT 中最大化浏览器窗口
【发布时间】:2018-05-14 08:34:01
【问题描述】:

我正在寻找一些解决方案,例如 Selenium WebDriver:

ChromeOptions options = new ChromeOptions();options.addArgument("--start-maximized");

所以在执行测试时浏览器窗口应该最大化。

我为这个问题找到了一个基于配置文件的解决方案,但是它打开了很多标签,这可能是由转义字符引起的。

@Test
    public void chromeWithProfileLaunch() throws Exception {
        String profileDir = "--user-data-dir=\"c:\\Temp\\profile1\""; //should be different folder every time
        String leanftChromeExtension = "--load-extension=C:\\Program Files (x86)\\HPE\\LeanFT\\Installations\\Chrome\\Extension"; //to load the LeanFT extension
        String homePage = "www.google.com"; //the homepage to start with

        new ProcessBuilder("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", profileDir, leanftChromeExtension, homePage)
            .start();

        Thread.sleep(2000); //wait for Chrome process to load

        Browser openedBrowser = BrowserFactory.attach(new BrowserDescription.Builder().title("Google").type(BrowserType.CHROME).build());

        Verify.areEqual(homePage, openedBrowser.getURL());
    }

【问题讨论】:

    标签: java google-chrome leanft


    【解决方案1】:

    我不知道最大化,但 LeanFT 支持将浏览器放入 fullScreen mode

    【讨论】:

      【解决方案2】:

      LeanFT不支持 maximize() 开箱即用。

      但是,您可以使用sendKeys() 方法。 我不完全确定您是否可以直接在browser 实例上使用它,或者您需要先getPage(),但您绝对可以发送Super 键(win 键)+ 指定here . 用于恢复到初始状态。

      如果您需要,这里有一个示例 using sendKeys with Java SDK

      【讨论】:

      • 我看到getPage() 没有sendKeys() 方法。
      • @plaidshirt 对不起,你是对的。 sendKeys 仅在 EditField 接口上受支持。你的页面上有这样的元素吗?如果不是,您可以暂时注入一个,但这将是一个 hacky 解决方案,我不能 100% 确定它会起作用
      • 是的,sendKeys() 也不稳定,我之前用过。也许 AutoIT 脚本可能是一个解决方案,但它不是那么轻量级的解决方案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 2014-10-31
      相关资源
      最近更新 更多