Error when using the click option

Hello,

I have the following script:

package automationFramework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstTestCase {

public static void main(String[] args) throws InterruptedException {
// Create a new instance of the Firefox driver
System.setProperty(“webdriver.gecko.driver”, “/home/gradulescu/Documents/Eclipse project/geckodriver.exe”);
WebDriver driver = new FirefoxDriver();

// Storing the Application Url in the String variable
String url = “http://demoqa.com”;

//Launch the Online Store Website
driver.get(url);

driver.findElement(By.xpath(“.//*[@id=’menu-item-374′]/a”)).click();
Thread.sleep (120);
driver.navigate().back();
driver.close();
}
}

 

What I want to do is to click the register button and then go back.

When I use the register command without the back, then it goes to register page and it stays there.

If I use the register command with the back command, it doesn’t goes to register page any more, or at least I cannot see, although I have put a 2 mins time out so that I could see.

 

Also, an error is generated in the console:

line 515: ReferenceError: accordion is not defined
JavaScript warning: https://www.googletagmanager.com/gtag/js?id=UA-109033876-1, line 68: unreachable code after return statement

 

Could you help me with this?

Thank you!

 

Add Comment
  • 1 Answer(s)

    Your code is correct just change thread sleep time from 120 milliseconds to 5000 milliseconds = 5 seconds so you will notice the actual page transitions.

    Your assumption that sleep parameter is in seconds is incorrect. It actually takes a value milliseconds.

    Default Answered on June 26, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.