ChromeDriver 2.33 的 driver.manage().window().maximize() 问题 [英] driver.manage().window().maximize() issue with ChromeDriver 2.33

查看:93
本文介绍了ChromeDriver 2.33 的 driver.manage().window().maximize() 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ChromeDriver 2.33 的发行说明说修复了导致调整大小/定位窗口命令在 Chrome 62+ 上失败的错误"但是当我使用 Chrome 62+ 浏览器时,这似乎仍然是一个问题.最大化 chrome 窗口使用 chrome 驱动程序导致以下异常.请问有人知道解决方案吗?

The release notes for ChromeDriver 2.33 says that ""Fixes a bug which caused Resizing/Positioning Window commands to fail on Chrome 62+" however this still seems to be an issue when i am using Chrome 62+ browser. Maximizing chrome window using chrome driver results in below exception. Does anyone know a solution please?

我注意到的另一件事是,虽然我从 https://chromedriver.storage.googleapis.com/index.html?path=2.33/,下面打印的日志显示驱动程序信息:chromedriver=2.25.426923!!

Another thing i noticed is, though i installed latest chromedriver (v2.33) from https://chromedriver.storage.googleapis.com/index.html?path=2.33/, the log printed below says Driver info: chromedriver=2.25.426923 !!

线程main"org.openqa.selenium.WebDriverException 中的异常:未知错误:无法从未知错误中获取自动化扩展:找不到页面:chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html(会话信息:chrome=62.0.3202.62)(驱动程序信息:铬驱动程序 = 2.25.426923(0390b88869384d6eb0d5d09729679f934aab9eed),平台=Windows NT10.0.15063 x86_64)(警告:服务器没有提供任何堆栈跟踪信息)

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html (Session info: chrome=62.0.3202.62) (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

推荐答案

正好有 2 个问题.

  1. 正如您所提到的,您已经安装了最新的 chromedriver (v2.33),但下面打印的日志显示驱动程序信息:chromedriver=2.25.426923,必须首先解决这个问题.您可以考虑从 Task Manager 手动杀死所有悬空的 chromedriver.exe 任务.此外,您可以考虑使用 CCleaner 从系统中清除所有腐烂的操作系统内容.如果需要,请重新启动系统.最后确保您在 System.setProperty() 中使用的 chromedriver.exe 的绝对位置确保chromedriver 二进制文件的版本为 2.33.

  1. As you mentioned, you have installed latest chromedriver (v2.33) but the log printed below says Driver info: chromedriver=2.25.426923, this issue must be addressed first. You can consider to manually kill all the dangling chromedriver.exe tasks from the Task Manager. Additionally you can consider to use CCleaner to wipe out all the rotten OS stuffs from your system. Take a system reboot if required. Finally ensure that what ever the absolute location of chromedriver.exe you are using within System.setProperty() ensure that the chromedriver binary is of version 2.33.

最后,建议使用 ChromeOptions 类来最大化 Web 浏览器,如下所示:

Finally, it is suggested to use ChromeOptions class to maximize the Web Browser as follows:

System.setProperty("webdriver.chrome.driver", "C:\\your_directory\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(opt);
driver.get("https://google.com");

  • 以下是一些可以解决您的问题的替代方案:

  • Here are some of the alternatives which may solve your question:

    • Using maximize() from WebDriver.Window interface :

    driver.manage().window().maximize();
    

  • 使用来自 WebDriver.Window 界面:

  • Using setSize(Dimension targetSize) from WebDriver.Window interface:

    driver.manage().window().setSize(new Dimension(800, 600));
    

  • 使用 addArguments("--start-maximized") 通过 ChromeOptions:

    chromeOptions.addArguments("--start-maximized");
    

  • 使用 addArguments("--window-size=1920,1080") 通过 ChromeOptions:

    chromeOptions.addArguments("--window-size=1920,1080");
    

  • 使用 JavaScriptExecutor 接口:

  • Using executeScript() from JavaScriptExecutor interface:

    ((JavaScriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");
    

  • 您可以在 Chrome - org.openqa.selenium.WebDriverException:未知错误:无法在 driver.manage().window().maximize();.

    这篇关于ChromeDriver 2.33 的 driver.manage().window().maximize() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆