【问题标题】:Selenium Chrome browser is getting launched but with error in consoleSelenium Chrome 浏览器正在启动,但控制台出现错误
【发布时间】:2016-10-23 00:17:12
【问题描述】:

我可以在下面/上面的代码的帮助下启动 Chrome 浏览器的空窗口,但它们是我遇到的一些错误

[3676:2080:0621/180047:ERROR:cache_util_win.cc(20)] Unable to move the cache: 0
[3676:2080:0621/180047:ERROR:cache_util.cc(134)] Unable to move cache folder C:\Users\Dhillon's\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache to C:\Users\Dhillon's\AppData\Local\Google\Chrome\User Data\ShaderCache\old_GPUCache_000
[3676:2080:0621/180047:ERROR:cache_creator.cc(129)] Unable to create cache
[3676:2080:0621/180047:ERROR:shader_disk_cache.cc(589)] Shader Cache Creation failed: -2

如果我使用 driver.get();命令它也不起作用

我使用的代码是:

package LearnStart;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumStart {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver",
                "C:\\Program Files         (x86)\\Google\\Chrome\\Application\\chrome.exe");
        WebDriver driver = new ChromeDriver();
        // driver.close();
        // driver.get("http://www.google.com");
    }

}

【问题讨论】:

标签: java selenium


【解决方案1】:

在这一行:

System.setProperty("webdriver.chrome.driver","C:\\Program Files         (x86)\\Google\\Chrome\\Application\\chrome.exe");

你设置的是chrome浏览器的二进制路径,这里应该设置的是chromedriver路径。

【讨论】:

  • 所以你说我们不能使用已安装的chrome浏览器
  • 顺便说一句,它现在可以工作了,但我不知道为什么它不适用于该路径!谢谢你
  • Selenium 需要驱动程序才能与浏览器对话。 chrome的驱动是chromedriver,需要下载。然后你需要告诉 selenium chromedriver 在你的文件路径中的位置。 Chromedriver 会自动为您找到您的 chrome 安装位置,并且它使用您的 chrome 安装。但是驱动是可以和chrome对话的,你的浏览器不能。
【解决方案2】:

如果您在浏览器的主副本工作时尝试启动新的浏览器副本,那就错了。他们俩都在尝试使用相同的缓存。避免这种情况的方法 - 只需复制您的用户数据,并将其附加到您的 Selenium 代码。

对不起,我只能提供 JS 代码:

    var webdriver = require('selenium-webdriver');
    var chrome = require('selenium-webdriver/chrome');
    var o = new chrome.Options();
    o.addArguments("user-data-dir=c:/Users/User/AppData/Local/Google/Chrome/User Data/");   

//(*)string that is above, connects your Chrome profile to Selenium

    var driver = new webdriver.Builder()
        .forBrowser('chrome')
        .setChromeOptions(o).build(); 

复制用户数据文件夹,并将副本的路径提供给 Selenium

o.addArguments("user-data-dir=c:/Users/User/AppData/Local/Google/Chrome/User Data Copy/");  

您可以沿此路径找到用户数据文件夹:

C:/Users/User/AppData/Local/Google/Chrome/用户数据

【讨论】:

    猜你喜欢
    • 2012-04-21
    • 1970-01-01
    • 2023-04-02
    • 2011-01-07
    • 2019-07-02
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 2022-01-05
    相关资源
    最近更新 更多