Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
URL未在使用Selenium java和windows操作系统的无头chrome中打开_Java_Google Chrome_Selenium_Headless - Fatal编程技术网

URL未在使用Selenium java和windows操作系统的无头chrome中打开

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

在使用Selenium java和Windows操作系统在chrome headless上运行脚本时,我面临以下问题。 URL未打开我的应用程序URL的页面标题为空..chrome驱动程序版本2.33,chrome浏览器62..我使用以下代码

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());
    

感谢您的回答,但它仍然不起作用。是否有任何额外条件来检查URL是否与headless automation兼容?@AmrutaPande首先请尝试。然后,您将能够检查您的url是否适合headless。答案没有错。答案很完美。嘿,谢谢回复…我确实检查了其他URL,他们工作正常,但不是我的:(这意味着我的应用程序URL不兼容?你介意共享你的URL吗?它在不运行headless时工作吗?是的..它在没有headless模式的情况下工作..不幸的是,我无法共享链接,因为它是官方链接..有没有办法确定URL是否与headless兼容?