microsoft / WinAppDriver

Windows Application Driver
MIT License
3.69k stars 1.4k forks source link

Dynamic wait in WinAppDriver #364

Open vikrampvr opened 6 years ago

vikrampvr commented 6 years ago

Hi !!

I have been trying to implement dynamic wait as below with no success.

WebDriverWait wait = new WebDriverWait(session, TimeSpan.FromSeconds(maxWaitTimeInSeconds)); wait.Until(ExpectedConditions.ElementExists(By.Name("something")));

The problem here is it seems like the "By" locator is not implemented in WinAppDriver which is present in "OpenQA.Selenium" namespace. without which im not sure how to implement explicit wait using WinAppDriver.

The below code works since we are passing the element to it and not the locator but the below condition is only if the element is already present and it just wait for the element to be enabled.

WebDriverWait wait = new WebDriverWait(session, TimeSpan.FromSeconds(maxWaitTimeInSeconds)); wait.Until(ExpectedConditions.ElementToBeClickable(element));

Is there anything i am missing here or is this still something to be implemented in WinAppDriver.

shankarkc commented 6 years ago

@vikrampvr I am doing like this if that helps...Here is my click wrapper implementation

do
        {
        WebElement element =  ((WindowsDriver) webDriver).findElement(by, using);
        try {
                if ( element != null ) {
                    element.click();
                    Thread.sleep(500);
                    return;
                }

            } catch (Exception e) {
                logger.debug("Couldnt find element using byType " +by + " locator " + using + " because of exception" + e.getMessage());
                attempt++;
                try {

                    Thread.sleep(500);
                } catch (InterruptedException e1) {
                    logger.debug("Exception while sleeping " + e.getMessage());
                }

            }
        } while (attempt < 5 );
        throw new WebDriverException("Couldnt find element using byType " +by + " locator " + using );
hassanuz commented 6 years ago

Hi @shankarkc , Can you open a ticket on the appium-dotnet-driver issue page here. They will be better able to assist you on this, as this appears to be outside WinAppDriver's scope.

brett-burkhart commented 6 years ago

@vikrampvr - here's how I accomplished this in C# for a login workflow scenario. After you login the code waits for the main window...

        loginWindow.FindElementByAccessibilityId("Submit").Click();

        var wait = new DefaultWait<WindowsDriver<WindowsElement>>(_session)
        {
            Timeout = TimeSpan.FromSeconds(60),
            PollingInterval = TimeSpan.FromSeconds(1)
        };
        wait.IgnoreExceptionTypes(typeof(InvalidOperationException));

        WindowsElement mainWindow = null;

        wait.Until(driver =>
        {
            driver.SwitchTo().Window(driver.WindowHandles[0]);

            mainWindow = driver.FindElementByAccessibilityId("MainWindow");

            return mainWindow != null;
        });

...not sure if this is best approach, but it works better than Thread.Sleep() IMHO since I cannot control how long it might actually take for the login process to complete and the main window to finally open.

vikrampvr commented 6 years ago

Thanks @shankarkc and @brett-burkhart As suggested by @hassanuz i have been following the dotnet driver development in Appium. And there seem to be issues in implementing implicit wait and page loads....seems like they are still working on it. Also implementing PageObjects in appium with C# seems to be having many issues. Not sure if anyone using WinAppdriver tried to implement page objects.

aloula commented 5 years ago

I'm facing the same issue, any news on that?

hassanuz commented 5 years ago

Hi @aloula.,

This seems to be an issue with the appium dotnet driver bindings - we encourage you to open a new issue here, so that they have visibility into this.

Thanks

aloula commented 5 years ago

Hi @aloula.,

This seems to be an issue with the appium dotnet driver bindings - we encourage you to open a new issue here, so that they have visibility into this.

Thanks

Thanks @hassanuz

jshinn6788 commented 5 years ago

Can someone provide an example of a dynamic wait in WinAppDriver using java?

sureshbogireddy commented 4 years ago

Facing below error : (unable to wait for element in opened window after app launch by entering login credentials with load spinner).

Error mesg : **org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters**

Tried waits as below but nothing worked : 1)WebDriverWait wait = new WebDriverWait(session,40); wait.until(ExpectedConditions.visibilityOf(session.findElementById("2A.5116A.4.B.F00D.1")));

2) session= new WindowsDriver(new URL(WindowsApplicationDriverUrl), cap);
session.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

3)capabilities properties : cap.setCapability("ms:waitForAppLaunch", "25");