I have this project where I have to automate the Play Store using Java and Appium.
Problem: The problem I am facing is, that it seems like the buttons in the Play Store are changing their id's dynamically. Let's say I run the program once, it works fine, but when I try for a second time it shows the element cannot be located.
I just want to press the install button and open button on the app page of the Google Play Store. I am facing this issue with just those buttons.
Code:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(100));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.TextView[@content-desc='Install']")));
WebElement installButton = driver.findElement(By.xpath("//android.widget.TextView[@content-desc='Install']"));
installButton.click();
System.out.println("Clicked on Install Button");
By openButtonLocator = By.xpath("//android.widget.TextView[@content-desc='Open']");
WebDriverWait wait2 = new WebDriverWait(driver, Duration.ofSeconds(400));
wait2.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.TextView[@content-desc='Open']")));
WebElement openButton = driver.findElement(openButtonLocator);
openButton.click();
System.out.println("Clicked on Open Button");
Please suggest solutions to effectively identify the install button and the open button. Presently I am using the UIAutomator2 Plugin in Appium.
(Note: I ensured that buttons are visible on the screen. Though the buttons are visible respective to wait times, but it's still not working.)