Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
229 views
by The go-to Tester (473 points)
retagged by
Here scenario is like

1. I click on LOGIN button from login page

2. Now instead of showing loading of home page after clicking on login button, its showing rolling of login button. And after random time home page display directly.

3. Now in 2nd steps , after clicking on login button, my script searching for element from home page.

So question is, how can i implement  wait for this home page element.

I used Thread.sleep(20000), but it is mandatory wait. I dont want this.

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

You can try using explicit wait or fluent wait.

Example of Explicit Wait.

WebDriver driver = new FirefoxDriver();
driver.get("http://yourwebsiteloginpage");
//Some action and click on login button and you move to 2nd step
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("identify your element")));

You can even try wait until element is clickable

wait.until(ExpectedConditions.elementToBeClickable(By.id("identify your element")));


Example of Fluent Wait:


WebElement countdown = driver.findElement(
                             By.id("your element here"));

        new WebDriverWait(driver,10).
                until(ExpectedConditions.visibilityOf(countdown));

        new FluentWait<WebElement>(countdown).
                withTimeout(10, TimeUnit.SECONDS).
                pollingEvery(100,TimeUnit.MILLISECONDS).
                until(new Function<WebElement  , Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return element.getText().endsWith("04");
                    }
                }
                );

by The go-to Tester (473 points)
Thans for reply. Solution suitable to my problem is
until(ExpectedConditions.presenceOfElementLocated(By.id("identify your element")));
by The go-to Tester (181 points)
Thank you for posting your solution.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...