Hi, I am very new to automation and possibly doing something very obviously wrong, but I can’t for the life of me figure out what is going wrong with this. I’m trying to automate a patient record system app on Android 7.0, and half of the elements in it have been set to clickable = false (We’ve put in a request to get the supplier to sort that out). I rummaged around on here and found that it’s possible to get a list of the elements by class name and then click on it via the index number. This worked a treat, it finds the element (Search icon) and then clicks it. Great… But as soon as I write and run my next line of code to find the next (clickable) element from the pop-up menu that subsequently opens, it throws up an error about now not being able to find the 1st search icon element. This is my code:
*This all works fine on its own
The app logs in, goes to the home page:
driver.findElementByAccessibilityId(“LoginUsername”).click();
driver.findElementByAccessibilityId(“LoginUsername”).sendKeys(“Xxxxx”);
driver.findElementByAccessibilityId(“LoginPassword”).click();
driver.findElementByAccessibilityId(“LoginPassword”).sendKeys(“Xxxxxxx”);
driver.findElementByAccessibilityId(“SmxLoginButton”).click();
Got it to wait for the Search icon to be visible at lease, but it is not clickable:
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("BannerSearchIcon")));
Then create a list and click on index no2 (Search icon):
List<MobileElement> Searchicon = driver.findElementsByClassName("android.widget.ImageView");
Searchicon.get(2).click();
Then from the pop-up menu that opens from the Search icon, click on the find patient option:
driver.findElementByXPath(("//*[@text = ‘Find Patient’]")).click();
Everything works fine until I add anything else to the code to move onto the next element. (This is a clickable element):
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text = ‘Search by first name’]"))).click();
As soon as I do this, it throws an error: Exception in thread “main” org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters… Element info: {Using=xpath, value=//*[@text = ‘Find Patient’]}
Even though it finds that element no problem before I add the code to go to the next step… What am I doing wrong?..
Using Appium 1.6.1, Intellij Idea, Android 7.0