I am a new bee for the automation and I have used the JUnit to develop the automation test script on using selenium webdriver on here my requirements
I have developed the automation test script. For some actions on my code, I want some time to execute the next command like find the element and load the pages so I use the Thread.sleep(). So now I found the info about using the Thread.sleep is a not good for the making test script
So my question is Can anyone say then how I give the dynamic wait time to my code My code is as below,
System.setProperty("webdriver.chrome.driver", "//path of the chrome driver");
driver = new ChromeDriver();
driver.get("https://url for my org");
Thread.sleep(5000); //to load the login page of my Org
driver.findElement(By.xpath("my login xpath")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("my login xpath")).sendKeys("username");
Thread.sleep(2000);
driver.findElement(By.xpath("my password xpath")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("my password xpath")).sendKeys("my password");
driver.findElement(By.xpath("login button")).click();
Thread.sleep(6000); //for giving the time to login Org
I have used the different type of the wait time on my code as per my requirement. If I go to the wait Class Can I able to achieve the same Wait time on there?
My question is different for the getting the explicit wait is provide the constant wait time to the different places like if we define the followingly,
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element_xpath")));
element.click();
//for another wait
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element_xpath")));
element.sendKeys("something"); //Here it's wait time(10 seconds) is same to the after the click action wait time.
So Why I am waiting the same time for all my wait section without need? if having another way please let me know?
If I am wrong please correct me.
Thanks.