selenium Only local connections are allowed
selenium踩过的一个坑,chromeDriver 不能打开页面,开始以为Only local connections are allowed是报错,只能打开本地的链接,百度了半天没找着解决办法
public class Auto {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\其他文件\\自动化驱动\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.baidu.com/?tn=48021271_15_hao_pg");
// driver.close();
}
}
运行得到的结果是这样的
这里只要给"www.baidu.com"加上‘https://’就可以打开百度了,然而控制台还是会输出红字Only local connections are allowed。
小技巧:
1.可以将所有的driver写入到path系统环境变量中 就可以省略:System.setProperty("webdriver.chrome.driver", "D:\\其他文件\\自动化驱动\\chromedriver.exe");
在使用Java Selenium进行自动化测试时遇到ChromeDriver无法打开页面的问题,错误提示为'Only local connections are allowed'。经过排查发现,需要在URL前添加'https://'才能正常打开网页,尽管如此,控制台仍然显示该警告。此外,分享一个小技巧,将ChromeDriver路径添加到系统环境变量PATH中,可以避免显式设置webdriver.chrome.driver。

2万+

被折叠的 条评论
为什么被折叠?



