-3

Error are as under:-

Multiple markers at this line

- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "Identifier (" to complete MethodHeaderName
- Syntax error on token ",", < expected
- Syntax error, insert "SimpleName" to complete QualifiedName

System.setProperty is a part of which jar file or where it is present? so that I can access it and use in my program.

public class Loginstepdef {

        System.setProperty("webdriver.chrome.driver","E:\\Selenium\\chromedriver\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();


        @Given("^I am on the login page of the application$")
        public void output()throws InterruptedException
        {
            driver.get("https://motzie-staging.mobile-recruit.com/login");
            //Navigation navigator=driver navigator();
            //navigator.to(http://10.10.5.56/login);

        }

        @When("^I login with username (.*) and password(.*)$")
        public void output2(String username, String password) throws InterruptedException 
        {
            //WebElement loginfield = driver.findElement(By.className("ng-scope"));
            WebElement loginfield = driver.findElement(By.id("username"));
            loginfield.sendKeys(username);
            loginfield.sendKeys(password);
            WebElement loginbutton = driver.findElement(By.className("ng-scope"));  
            loginbutton.click();
        }

        @Then("^Login successfully in that account$")
        public void output3() throws InterruptedException
        {
            System.out.print("login successfully");
        }

}              
luk2302
  • 55,258
  • 23
  • 97
  • 137

4 Answers4

0

\ is used for escape sequence, so it's giving you an error. Use / or \\ in the path

System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver\\chromedriver.exe"); 
Guy
  • 46,488
  • 10
  • 44
  • 88
  • I have also tried with / and \\ but the error remains same i.e System.setProperty("webdriver.chrome.driver","E:\\Selenium\\chromedriver\\chromedriver.exe"); please provide solution ASAP. – Romit Gupta Mar 19 '18 at 12:37
0

The Key and the Value with in System.setProperty are from Java System Class Method and both accepts String values. Hence pressing ctrl+space won't fetch you optimum results.

The error you are seeing is coming out of the Value field :

"E:\Selenium\chromedriver\chromedriver.exe"

You have to pass the absolute path of the WebDriver variant through either of the following options:

  • Escaping the back slash (\\) e.g. "E:\\Selenium\\chromedriver\\chromedriver.exe"
  • Single forward slash (/) e.g. "E:/Selenium/chromedriver/chromedriver.exe"

Note : You can find a detailed discussion in Exception in thread “main” java.lang.IllegalStateException:The path to the driver executable must be set by the : system property


Update

When you are using cucumber you have to put the initialization part of WebDriver within a method scope as follows :

WebDriver driver;

@Given("^Open Firefox and Start Application$")
public void Open_Firefox_and_Start_Application() throws Throwable 
{
    System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver\\chromedriver.exe");
    driver =  new ChromeDriver();
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Issue raised because you write it wrong. Use " \\ " or " /"

("webdriver.chrome.driver", "E:\\Selenium\\chromedriver\\chromedriver.exe");

Devdun
  • 747
  • 5
  • 14
  • I have also tried with / and \\ but the error remains same i.e System.setProperty("webdriver.chrome.driver","E:\\Selenium\\chromedriver\\chromedriver.exe"); please provide solution ASAP. – Romit Gupta Mar 19 '18 at 13:05
-1

Write it in main method:

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver","C:\\Users\\admin\\Downloads\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();;
    String url ="https://www.gmail.com";
    driver.get(url);
Aaron_ab
  • 3,450
  • 3
  • 28
  • 42