Selenium webdriver在最开始打开的时候浏览器的地址栏会出现data的解决方法
大家看下面的代码:
driver.get("http://www.baidu.com");
log.info("Navigation to url: " + driver.getCurrentUrl());
driver.navigate().to("http://www.cnblogs.com");
log.info("Navigation to url: " + driver.getCurrentUrl());
driver.navigate().back();
Thread.sleep(2000);
log.info("Back to url: " + driver.getCurrentUrl());
driver.navigate().forward();
Thread.sleep(2000);
log.info("Forward to url: " + driver.getCurrentUrl());
按道理输出应该是:
[BestPay Test] 2015-09-07 15:23:54,745 INFO main - Navigation to url: https://www.baidu.com/
[BestPay Test] 2015-09-07 15:23:56,743 INFO main - Navigation to url: http://www.cnblogs.com/
[BestPay Test] 2015-09-07 15:23:59,855 INFO main - Back to url: https://www.baidu.com/
[BestPay Test] 2015-09-07 15:24:03,536 INFO main - Forward to url: http://www.cnblogs.com/
但是我执行的时候一直出现一个错误,最开始打开的时候浏览器的地址栏会出现data;
[BestPay Test] 2015-09-07 15:25:38,704 INFO main - Navigation to url: https://www.baidu.com/
[BestPay Test] 2015-09-07 15:25:41,002 INFO main - Navigation to url: http://www.cnblogs.com/
[BestPay Test] 2015-09-07 15:25:43,607 INFO main - Back to url: data:,
[BestPay Test] 2015-09-07 15:25:46,315 INFO main - Forward to url: http://www.cnblogs.com/
第三行出现了问题, 这个经过在打开chrome时,添加了后面的语句即可解决:
options.addArguments("--user-data-dir="+System.getenv("USERPROFILE")+"/AppData/Local/Google/Chrome/User Data/Default");