相关疑难解决方法(0)

使用Java使用Selenium WebDriver加载Chrome配置文件

我遇到了一些让Selenium加载镀铬配置文件的麻烦.

String pathToChrome = "driver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", pathToChrome);

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
String chromeProfile = "C:\\Users\\Tiuz\\AppData\\Local\\Google\\Chrome\\User Data\\Default";
ArrayList<String> switches = new ArrayList<String>();
switches.add("--user-data-dir=" + chromeProfile);
capabilities.setCapability("chrome.switches", switches);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)

它开始很好并且工作得很完美,但是我想要加载默认配置文件,因为我想测试它,启用了一些Extensions并测试了一些首选项.

有没有人知道为什么这段代码不起作用?

我在Windows 7 x64上用Selenium 2.29.1和2.28.0以及chromedriver 26.0.1383.0测试了它.

java profile google-chrome selenium-webdriver

15
推荐指数
5
解决办法
7万
查看次数

保持用户登录 - 使用网络驱动程序保存cookie

这就是我想要使用WebDriver执行的操作.

  1. 使用选中的复选框登录该站点,保持用户登录.
  2. 关闭浏览器.
  3. 再次访问该站点并确保该用户已登录.

问题是当我关闭驱动程序并重新打开它时,我没有登录.

我的代码看起来像这样 -

   WebDriver myD = null;
    myD = new FirefoxDriver();
    String URL = "https://www.eurostylelighting.com/protected/account/signin?ReturnUrl=%2f";
    myD.navigate().to(URL);
    myD.findElement(By.cssSelector("input#txtEmailorRewards")).sendKeys("abc@yahoo.com");           
    myD.findElement(By.cssSelector("input#txtPassword")).sendKeys("abc");
    myD.findElement(By.xpath(".//*[@id='accountSignIn']/dl[4]/dd/label/span")).click();
Set<Cookie> cookies = myD.manage().getCookies();
    myD.close();
    myD= new FirefoxDriver();
    myD.navigate().to(URL);
for(Cookie getCookie:cookies)
            myD.manage().addCookie(getCookie);
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver selenium-webdriver

3
推荐指数
1
解决办法
7717
查看次数