Hello, I am trying to get the content from iOS clipboard. The idea is to long press on a build number on the app, which later pops up a playerID that comes out like this: PlayerID: 84848-848gb-488b-b48484.
Currently, the script below actually does the long press and shows the playerID and copy button when you long press, however, i have tried to retrieve the playerID by extracting it, but it throws this error:
Caused by: org.openqa.selenium.NoSuchElementException: Time out after waiting for element //*[contains(@name, 'PlayerID:')] for 10000 ms
The long press actually happens and the content comes up after the long press, but it seems after the clipboard pop-up comes up, it closes before it can find or extract the playerID.
This is the full implementation code that does the long press and tries to extract the playerID. The playerID is always different whenever there is a new session or the app starts, so here I am getting it dynamically:
FYI - This is the xpath of the element after inspecting //XCUIElementTypeStaticText[@name="PlayerID: 018e8de5-a3ff-4745-bded-ae05c5f1769e"]
WebElement theBuild = driver.findElement(By.id("settings_version"));
// Create a new instance of Actions
Actions action = new Actions(driver);
// Perform the long press action (with a duration)
action.clickAndHold(theBuild)
.pause(Duration.ofSeconds(2)) // Long press for 2 seconds
.release()
.perform();
// Construct the XPath with partial match for the accessibility ID
String xpath = "//*[contains(@name, 'PlayerID:')]";
// Find the element matching the XPath
WebElement playerIDElement = driver.findElement(By.xpath(xpath));
// Get the text value of the element, which represents the dynamic portion of
the accessibility ID
playerId = playerIDElement.getAttribute("name").replace("PlayerID: ", "");
// Print the retrieved dynamic part of the accessibility ID
System.out.println("Player ID: " + playerId);
My envrionment setup is:
- Appium version: 2.11.4
- XCUITest Driver: 7.26.4
- Simulator: iPhone 14 Plus
- iOS Version: iOS 18