java - The path to the driver executable must be set by the webdriver.gecko.driver system property; -
i using selenium 3.3.1
, i'm testing code below.
after running following error displayed:
exception in thread "main" java.lang.illegalstateexception: path driver executable must set webdriver.gecko.driver system property; more information, see https://github.com/mozilla/geckodriver. latest version can downloaded https://github.com/mozilla/geckodriver/releases @ com.google.common.base.preconditions.checkstate(preconditions.java:738) @ org.openqa.selenium.remote.service.driverservice.findexecutable(driverservice.java:111) @ org.openqa.selenium.firefox.geckodriverservice.access$100(geckodriverservice.java:38) @ org.openqa.selenium.firefox.geckodriverservice$builder.finddefaultexecutable(geckodriverservice.java:112) @ org.openqa.selenium.remote.service.driverservice$builder.build(driverservice.java:302) @ org.openqa.selenium.firefox.firefoxdriver.toexecutor(firefoxdriver.java:233) @ org.openqa.selenium.firefox.firefoxdriver.(firefoxdriver.java:125) @ org.openqa.selenium.firefox.firefoxdriver.(firefoxdriver.java:121) @ selenium_login.(selenium_login.java:13) @ selenium_login.main(selenium_login.java:70) /home/ali/.cache/netbeans/dev/executor-snippets/run.xml:53: java returned: 1 build failed (total time: 0 seconds)
java code:
import java.io.*; import org.apache.commons.io.fileutils; import org.openqa.selenium.by; import org.openqa.selenium.outputtype; import org.openqa.selenium.takesscreenshot; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.firefox.firefoxdriver; public class selenium_login { public webdriver driver = new firefoxdriver(); /** * open test website. */ public void opentestsite() { driver.navigate().to("http://testing-ground.scraping.pro/login"); } /** * * @param username * @param password * * logins website, entering provided username , * password */ public void login(string username, string password) { webelement username_editbox = driver.findelement(by.id("usr")); webelement password_editbox = driver.findelement(by.id("pwd")); webelement submit_button = driver.findelement(by.xpath("//input[@value='login']")); username_editbox.sendkeys(username); password_editbox.sendkeys(password); submit_button.click(); } /** * grabs status text , saves status.txt file * * @throws ioexception */ public void gettext() throws ioexception { string text = driver.findelement(by.xpath("//div[@id='case_login']/h3")).gettext(); writer writer = new bufferedwriter(new outputstreamwriter(new fileoutputstream("status.txt"), "utf-8")); writer.write(text); writer.close(); } /** * saves screenshot * * @throws ioexception */ public void savescreenshot() throws ioexception { file scrfile = ((takesscreenshot) driver).getscreenshotas(outputtype.file); fileutils.copyfile(scrfile, new file("screenshot.png")); } public void closebrowser() { driver.close(); } public static void main(string[] args) throws ioexception { selenium_login websrcapper = new selenium_login(); websrcapper.opentestsite(); websrcapper.login("admin", "12345"); websrcapper.gettext(); websrcapper.savescreenshot(); websrcapper.closebrowser(); } }
you need use geckodriver interact firefox since selenium 3.0. download geckodriver github depending upon os , extract geckodriver.exe
folder.
add following line before initializing webdriver
:
system.setproperty("webdriver.gecko.driver","c:/your/path/to/geckodriver.exe"); webdriver driver = new firefoxdriver(); ...
Comments
Post a Comment