I was trying to automate the hybrid app build using ionic2/Angular2 and typescript.
I am using C# for code writing. test are in BDD - specflow Versions: iOS:9.3.1 Xcode: 7.3 Appium: 1.4.13
I am not able to identify elements after swtiching Context to WEBVIEW.
Calling IOSDriver using below code
private IOSDriver driver = null;
public IOSDriver GetDriver(string platformVersion, string deviceName, string udid ,string appPath, string serverUri)
{
Capabilities iosCapabilities = new Capabilities();
DesiredCapabilities capabilities = iosCapabilities.Get(platformVersion, deviceName, udid, appPath);
driver = new IOSDriver(new Uri(serverUri), capabilities, TimeSpan.FromSeconds(Constants.DriverWaitTime));
driver.Manage ().Timeouts ().ImplicitlyWait (TimeSpan.FromSeconds(Constants.ImplicitWaitTime));
var contextNames = driver.Contexts;
driver.Context = contextNames[1];
driver.FindElement(By.Xpath(locator)).Click();
}
Setting Capabilities as
private DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability ("appium-version", Constants.AppiumVersion);
capabilities.SetCapability ("platformName", Constants.PlatformName);
capabilities.SetCapability("autoWebView", "true");
capabilities.SetCapability("browserName", "iOS");
capabilities.SetCapability ("platformVersion", Constants.PlatformVersion);
capabilities.SetCapability("deviceName", deviceName);
capabilities.SetCapability("app", appPath);
capabilities.SetCapability("udid", udid);
Am I setting the capabilities in correct way?
Solution tried:
1. I checked using browserName capbility as blank/safari but didn't worked
2. Also, I installed ios-webkit-debug-proxy and started proxy using terminal in background on my mac
Problem is I am not able to identify elements in WEBVIEW even after switching the context.
My Observation:->
After launching the app, in appium inspector I am able to see all the elements and I am trying to click on textbox to enter some value
Xpath of textbox(as i can view in appium inspector window):
"//UIAApplication[1]/UIAWindow[1]/UIAScrollView[2]/UIAWebView[1]/UIATextField[1]"
var contextNames = driver.Contexts
is giving me list to views(In my case 2 views: NATIVE_APP, WEBVIEW_1) WebView context is dynamically updating from 1,2,3 and so on..
As soon as I call
diver.Context=contextNames[1]; //setting context to WEBVIEW
and refresh the appium inspector I am not able to see/identify single element.Everything goes away.
Why I am not able to see/identify elements after switching to webview. (Note: As soon as I Switch back to driver.Context="NATIVE_APP" every element becomes visible in appium inspector but still I am not able to click)
Error is thrown as: "An element could not be located using given search parameter"
Manually also when I try to tap or sendkeys using appium inspector it is not letting me do so(after lauching tha app manually using inspector button). What is the issue here. Help would be highly appreciated
Error message as in appium window:
Error log on Appium Logs(Not able to view elements in WEBVIEW after switching context
Do verify the capabilities which I am using before switching the context. Thanks in advance