Get elements of a view (iOS)
1. Install WebDriverAgent
WebDriverAgent is a WebDriver server implementation for iOS that can be used to remote control iOS devices. We use it to get details about the elements of a view (label, name, class).
Run the following commands to install WebDriverAgent:
brew update
brew install node
npm install --global appium-webdriveragent
The Xcode project is located in the node_modules directory: [NPM_ROOT_PATH]/appium-webdriveragent/WebDriverAgent.xcodeproj
Replace NPM_ROOT_PATH by the result of the npm root -g
command.
Example:
Result of the
npm root -g
command: /opt/homebrew/lib/node_modulesPath of the Xcode project: /opt/homebrew/lib/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj
2. Prepare WebDriverAgent on Xcode for first use
Open a terminal and go where the project is:
cd [NPM_ROOT_PATH]/appium-webdriveragent/
Open the project with the following command:
open WebDriverAgent.xcodeproj
Connect the device to the computer via an USB cable
Go to Window > Devices and Simulators, and check that the device is connected
On Xcode, on the project navigator, click on “WebDriverAgent”
Select WebDriverAgentRunner among the targets, and the “Signing & Capabilities” tab
Check that the “Automatically manage signing” field is checked
Select a development team. We expect an error of bundle identifier (package name) because this one is already used.
Click on the “Build Settings” tab and write a new bundle identifier in the Packaging section
The “Signing & Capabilities” tab is then updated
Select IntegrationApp among the targets and follow the same steps
In the target choice on the top of Xcode, choose WebDriverAgentRunner and the right phone
3. Inspect elements of a view
Appium Server GUI : https://github.com/appium/appium-desktop
Appium Inspector : https://github.com/appium/appium-inspector
Steps to follow:
Open the WebDriverAgent project on Xcode
Connect the device to the computer via an USB cable
Go to Window > Devices and Simulators, and check that the device is connected
Build the project: Product > Build
Run the project: Product > Perform Action > Test Without Building
If it is the first time you run it on the device, you will get an error. In this case, go to Settings > General > Device management and trust WebDriverAgent.
Open Appium Server GUI
Click on “Start Server”
Open Appium Inspector
Complete the “Remote Path” field with the following text: /wd/hub
Complete the “Json Representation” field with your device properties:
You can click on “Saved capabilities sets” to use the saved settings.
Click on “Start Session”
On Appium Inspector, the phone screen appears. It is then possible to select elements of the screen to view their information (label, name, class), but also to scroll and click directly. Functions such as clickByText, waitUntilText and setTextByText search for the element label.
If any errors occur, refer to the associated troubleshooting page. : Troubleshooting iOS