Appium IOS Inspector without id or anything unique - ios

I'm trying (painfully) to access an iphone through appium
I finally managed to launch the app through appium but now I have an issue with the inspector.
Almost everything is a "UIACollectionCell" and the final objects for a example like a text don't have any id or content desc, it's just :
name = "mytext"
type = statictext
value = "mytext"
label = "mytext"
and then the xpath that apparently have all the object of the page (the visible on the screen and the non visible)
and looks something like
//UIAApplication[1]/UIAWindow[1]/UIScrollView[1]/UIACollectionView[1]/UIACollectionCell[2]/UIAStaticText[2]
is this normal ? do I still need to change parameter in the plist of the app or in the build settings or something else ?

In Appium, UIACollectionCell and UIAStaticText are ClassNames. name is AccessibilityId. So you can use className or accessibilityID or xPath.
Ex:
driver.findElementByClassName("UIACollectionCell").click();
driver.findElementByAccesiblityId("mytext").click();
driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIScrollView[1]/UIACollectionView[1]/UIACollectionCell[2]/UIAStaticText[2]
").click();

Related

Is it possible to add label field into device via Data Converter?

I would like to fill label and description fields without any manual work.
Or what is the best way for TB to fill those fields?
Label & Description in device
You should do it in the rulechain.
You should have in you rulechain tab the Root rule chain, add a script transformation node after the message filter one (you need to connect the two nodes with an Entity created tag if you want it to be done on every device).
to access the label and the description in the node you need "msg.additionalInfo.description" and "msg.label"
add the nodes to he existing root rule chain, and add an originator filter for device if you only want this to be done on devices
You can fill the Label via Data Converter ("deviceLabel" or "assetLabel" key). Description is not supported, yet.
Support was added in version 3.3.2:
https://thingsboard.io/docs/pe/reference/releases/#v332-november-11-2021
// Result object with device/asset attributes/telemetry data
var result = {
// Use deviceName and deviceType or assetName and assetType, but not both.
deviceName: 'Name',
deviceType: "Type",
deviceLabel: "Label",
attributes: {},
telemetry: {}
};

IOS XPATH through Appium

Hi I am trying to find xpath of toogle button to on and off for privacy setting in IOS device.
I tried with xpath:- xpath=${pro_on_off_ios} //XCUIElementTypeSwitch[#name="Link name and photo"].
and with this xpath switch is off and on vice versa,but I want to get the value of switch that its on/off and use as per our requirement.
I tried with that for value : ${Privacy_setting} AppiumLibrary.Get Text xpath=${pro_on_off_ios}.
but its not able to find.
Its solved,
I used get attribute and by value I got the desired result.
${setting}= GET ELEMENT ATTRIBUTE xpath=${//XCUIElementTypeSwitch[#name="Link name and photo"]} value

How to use dynamic localization keys with SwiftUI

I'm trying to display a localized text based on an ID. I have a lot of these, so it feels more efficient to just add dynamically the ID to the string.
The string file looks like this:
"users.1.name" = "Alice"
"users.2.name" = "Bob"
"users.3.name" = "Charles"
...
If I do the following, hardcoding the ID, it works as expected and displays the associated translated key:
Text("users.1.name")
However if I do this it only displays the string:
Text("users.\(user.id).name")
// displays "users.1.name" instead of "Alice"
I've also tried:
Text(LocalizedStringKey("users.\(user.id).name"))
// displays "users.1.name" instead of "Alice"
Am I missing something or is this not possible?
You need then the following. Tested with Xcode 11.4 / iOS 13.4
Text(NSLocalizedString("users.\(id).name", comment: ""))
I'm not a SwiftUI expert but you can use:
let key:String = "users.\(user.id).name"
Text(LocalizedStringKey(key))
// OR compact
Text(LocalizedStringKey(String("users.\(user.id).name")))

Testing iOS App on Simulator with Appium - Element Not Found

I'm using Appium client to record and generate the testing script for my iOS App.
On the App Inspector, I can tap on a login button and generate the script (in python) like below:
els1 = driver.find_elements_by_accessibility_id("login")
els1[0].click()
I can successfully log in to my app tapping the button on the App Inspector yet I got an error as I run the script on mac terminal:
els3[0].click()
IndexError: list index out of range
I tried different ways to access the button element by using accessibility id, name and class name, but none of the above work.
What did I miss? Is it a bug of the Appium software?
This error "IndexError: list index out of range" appears if we try to access list at index which is not present inside the list range
e.g.
thislist = ["apple", "banana", "cherry"] // here list index range is 0-2
thislist[1] = "blackcurrant" // this works fine as value of index is in range 0-2
But if I try below
// this is run time error i.e. "IndexError: list index out of range"
// as value of index is out of range 0-2
thislist[3] = "blackcurrant"
Note: List Index starts with 0
Consider a case where find_elements_by_accessibility_id("login") method does not return any element for any reason
els1 = driver.find_elements_by_accessibility_id("login");
And I try to access List els1 at 0 index which is empty so I get error "IndexError: list index out of range"
Now before accessing List we will check if List in not empty
els1 = driver.find_elements_by_accessibility_id("login")
if els1:
els1[0].click()
else :
print "Element not found and els1 array is empty"
After hours of googling and trying, I've found that the problem is about view refreshing.
Every time a view transition or navigation happens, it takes time to update the view. Once everything is updated the webDriver could successfully identify an element using the given search parameters.
So between every interaction just wait for a second:
el1 = driver.find_element_by_accessibility_id("login")
el1.click()
// wait for the view to get updated
driver.implicitly_wait(1)
els2 = driver.find_elements_by_name("Edit")
els2[0].click()
And the script would run as expected.

How to get list of child elements of an element in Appium?

I'm working with native iOS app through Appium.
I have the following structure:
UIAApplication ->
UIAWindow ->
UIATextBox
UIALabel
UIAWindow ->
SomethingElse
I have found a way to get the first UIAWindow and I'd like to get the list of all elements in that window. How do I do that?
I'd like to get UIATextBox and UIALabel from first UIAWindow but NOT SomethingElse element.
How do I do list of child elements in general?
#Test
public void testListWindows() {
List<MobileElement> windows = driver.findElementsByClassName("UIAWindow");
List<MobileElement> elements = windows.get(0).?????
}
You're almost there. What you have is giving you a list of all UIAWindows when what you want is a list of all the elements of the first UIAWindow. I'd suggest using Xpath with a wildcard.
This will get you every element that is a direct child of the first UIAWindow:
List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]/*");
And this will get you every child and sub-child and sub-sub-child etc. of the first UIAWindow:
List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]//*");
An extra tip: If you're automating for iOS, I assume that means you have access to OS X, where you can install the Appium dot app and use inspector. The inspector is a great tool to test out xpath queries before putting them into your code.
You can also find textfield and label by its class for iOS app in Appium. findElementsByClassName method will return all elements on current screen that matches that class.
List<MobileElement> textFields = driver.findElementsByClassName("UIATextField");
MobileElement textField = textFields.get(0);
List<MobileElement> labels = driver.findElementsByClassName("UIAStaticText");
MobileElement label = labels.get(0);

Resources