用java+selenium启动chrome浏览器时报错Exception in thread "main" org.openqa.selenium.NoSuchSession
来源:互联网 发布:申请淘宝网店要多少钱 编辑:程序博客网 时间:2024/05/21 20:24
现在很多网页内容都是动态生成的,动态页面信息的提取可以使用selenium。提取动态页面信息的
其中一种方法就是启动浏览器执行js代码,那么第一步就是要先启动浏览器。
下面上代码:
import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;public class ChromeTest{public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver_win32\\chromedriver.exe"); //新建一个WebDriver 的对象,但是new 的是chrome的驱动 WebDriver driver =new ChromeDriver(); //打开指定的网站 driver.get("http://www.baidu.com"); System.out.println(driver.getTitle()); /** * dr.quit()和dr.close()都可以退出浏览器,简单的说一下两者的区别:第一个close, * 如果打开了多个页面是关不干净的,它只关闭当前的一个页面。第二个quit, * 是退出了所有Webdriver所有的窗口,退的非常干净,所以推荐使用quit最为一个case退出的方法。 */ driver.quit();//退出浏览器}}运行结果如下图:
以上结果没有输出“百度一下,你就知道”,因此出现错误。此错误让我纠结了很长时间,最终终于解决。
大家仔细看的话,可以看到上图中所报出的一个warning:The server did not provide any stacktrace information
其实,在这里代码是没有错的,造成错误的原因是我用的chromedriver版本与chrome浏览器的版本不对应。
两者之间的映射关系可参照这位老兄的博客:http://blog.csdn.net/huilan_same/article/details/51896672
然后我下载了一款对应我chrome浏览器版本的chromedriver,再次运行代码结果如下:
这样就OK了。
阅读全文
0 0
- 用java+selenium启动chrome浏览器时报错Exception in thread "main" org.openqa.selenium.NoSuchSession
- Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException
- Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException
- Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException
- Selenium+webDriver 启动IE11 浏览器报错“org.openqa.selenium.NoSuchWindowException”
- Selenium+webDriver+win10 启动IE11 浏览器报错“org.openqa.selenium.NoSuchWindowException
- TestSuite很多skipped,报错Exception org.openqa.selenium.SessionNotCreatedException
- JUnit4.11命令行运行时报错Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescrib
- org.openqa.selenium.StaleElementReferenceException
- org.openqa.selenium.StaleElementReferenceException
- org.openqa.selenium.ElementNotVisibleException
- hive 启动时报错: Exception in thread "main" java.lang.RuntimeException: java.lang.
- Appium报错:org.openqa.selenium.NoSuchSessionException
- selenium exceptionin java (org.openqa.selenium.remote.UnreachableBrowserException)
- selenium异常:org.openqa.selenium.remote.UnreachableBrowserException
- hive启动时报Exception in thread "main" java.lang.NoClassDefFoundError错误
- Java Code Examples for org.openqa.selenium.JavascriptExecutor
- java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver 问题解决方案
- XGBoost参数调优完全指南
- angular jquery实现用户表
- Python编写基于socket的非阻塞多人聊天室程序(单线程&多线程)
- 坐标转移
- 嵌入式技术的就业前景
- 用java+selenium启动chrome浏览器时报错Exception in thread "main" org.openqa.selenium.NoSuchSession
- 八(1) 5
- 自定义view画圆
- ProgressService下载图片
- SDUT-1273 面向对象程序设计上机练习十一(运算符重载)
- Idea创建web项目
- Linux作业二
- Android SqlLite的简单实用
- 自考总结-2017.10