I have written the below code to login to the website "qtpselenium.com".
The below code works just fine if i give Thread.sleep in between to make the code execution halt for some time. If I comment the Thread.sleep, the code doesn't work as expected. I have tried to use implicit and explicit waits of selenium to make driver to wait for the element to be visible but the code only works as expected when i use the Thread.sleep.
Is there any way I can make the below code to work without using the Thraed.Sleep statement.
and is it a bad practice to use Thread.sleep statements in the selenium code?
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
public class QTPSelenium {
public static WebDriver driver = null;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://qtpselenium.com/");
driver.findElement(By.xpath(".//*[@class='btn btn-default member_login']")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("(//button[@type='submit'])[3]")).click();
Thread.sleep(10000);
driver.findElement(By.id("email")).sendKeys("Some Email ID");
driver.findElement(By.id("login-password")).sendKeys("Some Password");
driver.findElement(By.xpath("html/body/main/div[2]/div/div/div[1]/div/div/div/form/button")).click();
}
}