第一次启动浏览器驱动报错
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
原因:驱动版本不对,驱动没有放在安装目录下
我的错误原因:System.setProperty("webdriver.chrome.driver", "D:\\Chrome\\Application\\drivers\\chromedriver_win32\\chromedriver.exe");中的"webdriver.chrome.driver", webdriver少写了driver
启动之后报错
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
这是因为Chrome没有放在默认浏览器目录下导致的,更改目录和环境变量配置启动正确
调试多选框的时候出错
Exception in thread "main" org.openqa.selenium.InvalidElementStateException: invalid element state
但是有输出。说明输出语句正常,后面的clear出错。注释掉就没了。在多选框中,这个是没用的
两个方法连着调用,但是后面一个方法没有执行完
原因:上一个的休眠时间太长。针对不同的元素有不同的方法,所以需要在一个元素执行完之后休息一段时间
下拉框创建Select报错
Class 'Anonymous class derived from Select' must either be declared abstract or implement abstract method 'accept(Visitor)' in 'Instruction'
已知Select是下拉框对象,是需要传网页元素进去的,不存在抽象说法。查看之后发现,自动导包错误,改成selenium的包即可
Actions新建对象报错
Action action = new Action(driver);
显示这个类是抽象类,不能传参数。
先排除导包错误,后面发现是Actions写成了Action。。。