dotnet-client
dotnet-client copied to clipboard
Explicit Wait not working in Appium 1.8.0 with c# client
Description
Explicit wait not working and the sever doesn't wait for the time specified for the object to be present
Environment
Appium version 1.8.0 Desktop OS/version used to run Appium: Windows 10 Pro Node.js version (unless using Appium.app|exe): 8.10.0 Mobile platform/version under test: Android API 25 ,v7.1.1 Real device or emulator/simulator: Real Device Samsung Tab Appium CLI or Appium.app|exe: both IDE: VisualStudio 2017 Enterprise and C# as coding language
Code To Reproduce Issue [ Good To Have ]
new WebDriverWait(driver, TimeSpan.FromMilliseconds(50000)).Until(ExpectedConditions.ElementToBeClickable(By.ClassName("android.widget.Spinner")));
and also tried this code
new WebDriverWait(driver,FromMilliseconds(50000)).Until(X=>X.FindElement(By.Id("elementid");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(50)); Func<IWebDriver, IWebElement> waitForElement = new Func<IWebDriver, IWebElement>((IWebDriver Web) => {
IWebElement element = Web.FindElement(By.XPath("//android.widget.Button[@text='OK']"));
if (element.GetAttribute("style").Contains("red"))
{
return element;
}
return null;
});
IWebElement ok =wait.Until(waitForElement);
Ecxeption stacktraces
Test Name: TestMethod1 Test FullName: UnitTestProject1.UnitTest1.TestMethod1 Test Source: C:\Users\gokulnath.kumar\source\repos\UnitTestProject1\UnitTestProject1\UnitTest1.cs : line 25 Test Outcome: Failed Test Duration: 0:01:49.3963396
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Appium.AppiumDriver
1.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath) at OpenQA.Selenium.By.<>c__DisplayClass19_0.<XPath>b__0(ISearchContext context) at OpenQA.Selenium.By.FindElement(ISearchContext context) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) at OpenQA.Selenium.Appium.AppiumDriver
1.FindElement(By by)
at AMCS_Mobile.Page_Objects.Vehicle_Selector_Objects.OK_btn() in C:\Users\gokulnath.kumar\source\repos\UnitTestProject1\UnitTestProject1\Page_Objects\Vehicle_Selector_Objects.cs:line 36
at AMCS_Mobile.Vehicle_Selector.Vehicle_selector.Vehicle_Selector(String Vehiclename) in C:\Users\gokulnath.kumar\source\repos\UnitTestProject1\UnitTestProject1\App_Modules\Vehicle_selector.cs:line 30
at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\gokulnath.kumar\source\repos\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 29
Result Message:
Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception:
System.InvalidOperationException: An element could not be located on the page using the given search parameters.
Link to Appium logs
https://gist.github.com/Gocoollnath/547096033a7ff6a9bc4c89b9f30f7d1b
I am running into the same issue. When I use WebDriverWait it does not appear to actually wait for the time specified.
I also seem to be running into this issue :-/
I'm having the same issue. Appium CLI: 1.8.1 Appium app: 1.6.3
Any workaround?
Same issue using Appium.WebDriver 3.0.0.2. WebDriverWait does not wait for the time specified.
Having the same issue with Selenium.WebDriver 3.141.0. Any plan to fix this?
Using
new WebDriverWait(Driver, timeout).Until(func);
is working fine for us. Are you aware that the passed function needs to return a boolean?
Maybe you can try one of these
new WebDriverWait(driver, FromMilliseconds(50000)).Until(drv => drv.FindElement(By.Id("elementid")).Displayed);
or
new WebDriverWait(driver, FromMilliseconds(50000)).Until(drv => drv.FindElements(By.Id("elementid")).Any());
I have to say that I also did not have much success when using ExpectedConditions (so I can give no guidance here).
This is not working for me either. Tried various WinAppDriver versions. Works fine with the webdrivers.
I am having this issue with Selenium IDE (we still haven't moved forward with another automation tool) All my "Wait for element present" commands just spin. But if I pause my test and un-pause, it then goes forward.
Facing the same issue using Appium.WebDriver 4.2.1. I am using DefaultWait and it does not wait for the time specified. I set a wait time of 5 seconds. But it is taking more than that(sometimes even 20+ seconds) Any update on this ?
I did a bit research of this issue, but not totally sure about the second point
- Quite obvious that the ImplicitWait time has to be smaller than the one you passed to WebDriverWait. So you need to set it to a small amount and set back to the original value after the WebDriverWait.
- The WebDriverWait is expecting a NotFoundException when element not found. But seems appnium (maybe not from appnium) is throwing WebDriverException instead.
I guess below would workaround the issue
WebDriverWait GetWebDriverWait(IWebDriver driver, TimeSpan waitTime)
{
var wait = new WebDriverWait(driver, waitTime);
wait.IgnoreExceptionTypes(typeof(NotFoundException),
typeof(InvalidOperationException), // i guess some version may throw this exception instead.
typeof(WebDriverException));
return wait;
}
UseTheWebDriverWait() {
using(Disposable(onInit: SetImplicitWaitTimeToSmallerAmount, onDispose: SetImplicitWaitTimeBack)){
var wait = GetWebDriverWait(theDriver, theTimeToWait);
wait.Until(......);
}
}
@EbenZhang Adding IgnoreExceptionTypes worked for me but when this is going to be fixed?
@Gocoollnath Can you please try with appium 2.0? Appium 1.0 is out of support
Closing this issue since it's the expected behavior.
As @EbenZhang mentioned, you should use:
wait.IgnoreExceptionTypes(typeof(NotFoundException)
.
In addition, you should wrap your code with try-catch, in case element is not found in the given time frame.