Appium + iOS + Java how to get URL that I've just clicked? Appium + iOS + Java how to get URL that I've just clicked? selenium selenium

Appium + iOS + Java how to get URL that I've just clicked?


Although getCurrentUrl is working for Android when the web browser opens as in a different context than the "Native APP" context, it is not implemented for iOS XCUITest when Safari opens as "Native APP" context.

In the case of iOS(Safari) you can use the following:

wait until safari app opens(wait till next Statement is True):

appiumDriver.queryAppState("com.apple.mobilesafari").toString().equals("RUNNING_IN_FOREGROUND")

Then click on the URL Bar and get the TextValue of it:

MobileElement urlToolBar = appiumDriver.findElement(By.xpath("//XCUIElementTypeOther[@name='URL']"));urlToolBar.click();appiumDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//XCUIElementTypeTextField[@name='URL']")));MobileElement urlTextFied = appiumDriver.findElement(By.xpath("//XCUIElementTypeTextField[@name='URL']"));String desiredUrl = urlTextFied.getText();

In case Page Factory is used within the project then replace findElement with @iOSXCUITFindBy