Issue
I'm new to Appium but quite experienced with Selenium.
The first action, clicking on the Element 'Nieuw' is giving no problem, a screen with four choices appears.
After that I'm trying to click on an Element with accessibility id 'Proefitmanager'. In Appium desktop this is giving no problem but in my Appium test I'm getting a NoSuchElement exception. I'm using the Id which is suggested by Appium desktop and my code is comparable with the code generated by the recorder of Appium Desktop although I'm using C# instead of Java.
IWebElement nieuw = (IWebElement)driver.FindElementByXPath("(//android.view.View[@content-desc='Nieuw'])[2]");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(nieuw));
nieuw.Click();
IWebElement proefrit = (IWebElement)driver.FindElementByAccessibilityId("Proefrit");
wait.Until(ExpectedConditions.ElementToBeClickable(proefrit));
proefrit.Click();
My idea is that the element has no focus at the moment of clicking because it is in another frame or so. I tried to use SwitchTo().Frame(0) and Frame(1) but this is given exceptions like:
Could not proxy command to remote server. Original error: 404 - undefined`
See image from Appium desktop to have an Idea what the app looks like.
Solution
- Firstly you need to switch from Native View to Web View before clicking on "Proefit" element.
Here is the sample code in Java:
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName); //prints out something like NATIVE_APP or WEBVIEW_1
}
driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1
- Then Perform the click operation on the proefit element.
Here is the sample code in Java:
WebElement proefrit=driver.findElementByAccessibilityId("Proefrit");
wait.Until(ExpectedConditions.ElementToBeClickable(proefrit));
proefrit.click();
3.Then switch back to Native Context to continue with the test.
driver.context("NATIVE_APP");
Answered By - Uday Seshadri
Answer Checked By - Mary Flores (JavaFixing Volunteer)