[iOS 10.1] [Appium 1.6.3] [C#] Can't access elements in WebView

The contexts change each time I run my tests, so I have developed a method to iterate through each context and attempt to find an element with an ID. I am unable to find this element in any context.

Here is my setup:

  • Appium Version: 1.6.3 (w/ WDA patch)
  • iOS Version: 10.1
  • Simulator (iPhone 7)

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(“platformName”, ConfigurationManager.AppSettings[“platformName”]);
capabilities.SetCapability(“platformVersion”, ConfigurationManager.AppSettings[“platformVersion”]);
capabilities.SetCapability(“deviceName”, ConfigurationManager.AppSettings[“device_name”]);
capabilities.SetCapability(“app”, ConfigurationManager.AppSettings[“appPath”]);
capabilities.SetCapability(“newCommandTimeout”, “600”);
capabilities.SetCapability(“automationName”, “XCUITest”);

driver = new IOSDriver(new Uri(“http://172.xx.xx.xxx:4723/wd/hub”), capabilities, TimeSpan.FromSeconds(300));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(ImplicitWaitTime));

Here is my code:

private void DetermineWebviewContext()
{
    IReadOnlyCollection<string> adf = driver.Contexts;
    foreach (string s in adf)
    {
        Debug.WriteLine("Context: " + s);
        driver.Context = s;
        try
        {
            WebDriverWait w = new WebDriverWait(driver, System.TimeSpan.FromSeconds(10));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
            w.Until(ExpectedConditions.ElementIsVisible(By.Id("chkDefaultShip")));
            break;
        }
        catch (Exception e)
        {
            Debug.WriteLine("Unable to find element using context: " + driver.Context + "; Error: " + e.Message);
        }
    }
}

Here is the Debug output:

Debug Trace:
Context: NATIVE_APP
Unable to find element using context: NATIVE_APP; Error: Timed out after 10 seconds
Context: WEBVIEW_1018.1
Unable to find element using context: WEBVIEW_1018.1; Error: Timed out after 10 seconds
Context: WEBVIEW_1018.5
Unable to find element using context: WEBVIEW_1018.5; Error: Timed out after 10 seconds
Context: WEBVIEW_1018.11
Unable to find element using context: WEBVIEW_1018.11; Error: Timed out after 10 seconds
Context: WEBVIEW_1018.12
Unable to find element using context: WEBVIEW_1018.12; Error: Timed out after 10 seconds
Context: WEBVIEW_1018.13
Unable to find element using context: WEBVIEW_1018.13; Error: Timed out after 10 seconds
Context: WEBVIEW_1018.15
Unable to find element using context: WEBVIEW_1018.15; Error: Timed out after 10 seconds
Context: WEBVIEW_1023.1
Unable to find element using context: WEBVIEW_1023.1; Error: Timed out after 10 seconds

I have attempted using a locator found through the Appium Inspector and by looking at the webview in my browser and inspecting the elements but both locators yield the same results.

Any help would be much appreciated as this is the last step in completing my core smoke test for the app I am testing.

Update on this, I am able to automate this webview using the 'NATIVE_APP' context on an iPhone 6 (real device and simulator) but not on the 7. I’m confused as to how this is even working at all using that context…

hey man did you ever found solution to that ?