-6

I am automating an application were , Explicit wait is not working .

My requirement is to wait for a particular element until it is loaded/ visible or clickable to perform next action.

I tried all the expectedconditions in explicit but it failed. only sleep is working.

One thing that i have noticed is that , web browser is not load but page is loading and hence the explicit functionality doesnt work.

Could some one help me in this?

Please find the attached

Arun Chettur
  • 43
  • 2
  • 10
  • 3
    I have downvoted this question because you are asking us about a bug without showing us code. Without concrete code, we can only guess what the problem might be, which is not useful to you or future readers. If you can [edit] your question to show us a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) of your problem, this downvote may be retracted. – Joe C Mar 06 '18 at 06:51
  • 1
    Besides the code, it is also important to know which exceptions occur,TargetInvocation, ElementNotVisible etc. – Frank Mar 06 '18 at 08:16
  • Hi All.I have reedited my posted with screenshot and dom elements for that particular wrapping. – Arun Chettur Mar 07 '18 at 08:07

4 Answers4

0

Due to the fact that your question is rather general I can only provide a general answer at this point. You could wait until your page as a whole has been loaded before you proceed with the testing. (I would suggest this as you claim to have issues where the browser does not seem to be completely ready when you proceed with your testing)

This can be done using the following code:

IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"))

*This code is not mine it has been sourced from
Wait for page load in Selenium

Karan Shishoo
  • 2,402
  • 2
  • 17
  • 32
0

Explicit Wait i.e. WebDriverWait is proven & efficient and it is working just perfect in conjunction with ExpectedConditions.

As your requirement is to wait for a particular element until it is loaded/ visible or clickable to perform next action you can use the below block of code :

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.id("myDynamicElement")));
myDynamicElement.click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

This type of issues occurs when the web element takes little more time to load than usual time. In this case, we have use polling mechanism in the given interval which is fluentWait. Below is the helpful code.

public WebElement fluentWait(final By locator) {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(10, TimeUnit.SECONDS)
                .pollingEvery(1, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

        WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver _driver) {
                return driver.findElement(locator);
            }
        });
        return  foo;
    };
0

There is three type of wait in selenium.

  • implicit Wait
  • Explicit Wait
  • Fluent Wait

Implicit Wait

driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

Explicit wait

WebDriverWait wait = new WebDriverWait(WebDriver,TimeOut);

Fluent Wait

Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);

Fore more information how to use all wait with example please go to below URL.

https://trickyautomationworld.blogspot.in/2018/02/implicit-wait-vs-explicit-wait-vs.html