首先,安裝並配置JDK,安裝eclipse,安裝firefox和chrome。下載selenium語言的JAVA庫文件,下載地址為,如果打不開,則需要翻牆;
http://www.seleniumhq.org/download/;
其次, 在eclipse中新建項目,在新建項目中將下載的selenium的所有以 .jar為后綴的文件導入項目;導入方式:右鍵項目名-->build path-->config build path-->java build path-->libraries-->add External jarars
然后,新建測試編寫代碼,開始運行;運行報錯“”Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see
https://github.com/mozilla/geckodriver. The latest version can be downloaded from
https://github.com/mozilla/geckodriver/releases“” 因為是用的selenium3,所以需要在谷歌上下載驅動程序,下載地址
https://github.com/mozilla/geckodriver/releases/tag/v0.9.0,根據系統版本選擇。解壓后放到chrome的瀏覽器按照目錄,並添加代碼
System.setProperty("webdriver.chrome.marionette","C:\\Program Files (x86)\\Google\\Chrome\\Application\\geckodriver.exe");
運行結果,打開了瀏覽器並訪問了正確的地址,就對了。
