URL未在使用Selenium java和windows操作系统的无头chrome中打开
在使用Selenium java和Windows操作系统在chrome headless上运行脚本时,我面临以下问题。 URL未打开我的应用程序URL的页面标题为空..chrome驱动程序版本2.33,chrome浏览器62..我使用以下代码URL未在使用Selenium java和windows操作系统的无头chrome中打开,java,google-chrome,selenium,headless,Java,Google Chrome,Selenium,Headless,在使用Selenium java和Windows操作系统在chrome headless上运行脚本时,我面临以下问题。 URL未打开我的应用程序URL的页面标题为空..chrome驱动程序版本2.33,chrome浏览器62..我使用以下代码 System.setProperty("webdriver.chrome.driver", chromedriver.exe); ChromeOptions chromeOptions = new ChromeOptions(); chromeOption
System.setProperty("webdriver.chrome.driver", chromedriver.exe);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("window-sized1200,600");
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("app url");
System.out.println(driver.getTitle)
是不是因为不支持按应用程序URL的无标题模式..没有得到任何异常..窗口大小参数中有一个输入错误,您调用了
addArguments
,但每次调用仅添加一个参数,请尝试此操作
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless", "window-size=1200,600");
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("your.app.url");
System.out.println(driver.getTitle)
你必须考虑以下几个变化:
- 执行操作时,System.setProperty提供
二进制文件的chromedriver
绝对路径
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
- 窗口大小的
参数是
选项代码>
chromeOptions.addArguments("window-size=1400,600");
driver.get("https://www.google.co.in");
System.out.println(driver.getTitle());
- 执行driver.get()时,请包括
和https
www
chromeOptions.addArguments("window-size=1400,600");
driver.get("https://www.google.co.in");
System.out.println(driver.getTitle());
- 要检索页面标题,方法是
getTitle()
chromeOptions.addArguments("window-size=1400,600");
driver.get("https://www.google.co.in");
System.out.println(driver.getTitle());
- 修改后的代码块如下所示:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe"); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--headless"); chromeOptions.addArguments("window-size=1400,600"); WebDriver driver = new ChromeDriver(chromeOptions); driver.get("https://www.google.co.in"); System.out.println(driver.getTitle());