IOS XPATH through Appium - ios

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

Related

How to find multiple element in appium having same id in Python?

I am writing test code in Appium of an Andriod Project in python . The problem is that I am not able to access two button in two different Activity having same Id . I have tried to access the second button in this way.But none of them works. How to resolve the issue?
driver.find_element_by_id("com.myapp.testApp:id/login[1]").click(), driver.find_element_by_class_name("android.widget.Button").click()
driver.find_element_by_xpath("(//button[#id='login'])[1]").click()
driver.find_element_by_xpath("//android.widget.Button[#text='Change Password']").click()
Use .find_elements*:
elements = driver.find_elements_by_xpath("xpath")
#check elements number
print(len(elements))
#click second element
elements[1].click()
Can you try with textview:
driver.find_element_by_xpath("//android.widget.TextView[#text='Change Password']").click()
If buttons texts are different, try by accessibility_id
driver.find_element_by_accessibility_id("Login").click()
driver.find_element_by_accessibility_id("Change Password").click()
OR
If you are familiar with uiautomator,
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.myapp.testApp:id/login[1]")')
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.myapp.testApp:id/login[2]")')
You can use the get method with findElements:
driver.findElements(By.xpath("yourXpath]")).get(0).click();
You can do link this, It will give you proper Output:
Input is:
d1 = driver.find_elements_by_id("com.application.zomato:id/price")
itemtotalprice = d1[0].get_attribute("text")
Here, is my output:
Mandarin Oak
₹200
₹166.75

Not able to get adjustToPickerWheelValue in xctest

I am trying to select a value in picker wheel but every time I type [app.pickerWheels.adjustToPickerWheelValue[#"Test"]];
Xcode says
Property 'adjustToPickerWheelValue' not found on object of type 'XCUIElementQuery'
How to resolve this issue ?
Here is the link i followed till now Link
UIElement Tree
adjustToPickerWheelValue is a method on XCUIElement, but you are using it on an XCUIElementQuery.
To get an XCUIElement, you must specify which picker wheel you want (even if there is only one).
let pickerWheel = app.pickerWheels.elementBoundByIndex(0)
pickerWheel.adjustToPickerWheelValue("some value")

Appium IOS Inspector without id or anything unique

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();

UIAutomation - Check the message in Alert and compare it with expected message

I am working on alerts in UIAutomation. When I encounter an alert, I am supposed to ensure that the alert title and message are the same as expected. I have done this to get access for alert title.
var AlertTitle = target.frontMostApp().alert().name();
UIALogger.logMessage(AlertTitle);
In the similar way, is there any way to retrieve the message in alert ? I have tried using
target.frontMostApp().alert().value();
but it did not work. I have logged the element tree and got this.
UIAAlert
|
UIAImage
UIAStaticField name: Abc value: ABc
UIAStaticField name: XYZ value: XYZ
UIAButton
I need to retrieve the value of second UIAStaticField in this alert and compare with expected value. How do I do that ?
I tried doing this but it didn't work.
target.frontMostApp().alert().staticTexts[1]().value();
In iOS 7, it appears they wrap the staticTexts in a scrollView, so you'll need to alter Jonathan's answer to be:
target.frontMostApp().alert().scrollViews()[0].staticTexts()[1].value();
You're so close! You've got the parentheses and brackets backward in your line. Do it this way:
target.frontMostApp().alert().staticTexts()[1].value();
That way, you are calling the staticTexts() method on the alert to get the element array and then using the bracket syntax to get the second element.

display seconds in DateTimeItem (SmartGWT)

when reading SmartGWT DateTimeItem: accept 12 hour format I found that using TimeDisplayFormat offers the options to display the seconds as, e.g. dateTimeItem.setTimeFormatter(TimeDisplayFormat.TOPADDED24HOURTIME); well, but there was no change in the displaying of the date.
As the code states that TimeDisplayFormat is deprecated, and one should use the DateDisplayFormatter instead, I tried dateTimeItem.setDateFormatter(DateDisplayFormat.TOSERIALIZEABLEDATE);, but still no change.
The value gets set via dateTimeItem.setValue(myDate);
Any idea what (else) I have to set to the DateTimeItem in order to get the seconds displayed as well?
I'm using SmartGWT 3.1
PS: I tried dateTimeItem.setDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE); as well, but still no change
It seems DateDisplayFormat.TOSERIALIZEABLEDATE is having some issue in SmartGWT 3.x.
dateTimeItem.setDateFormatter(DateDisplayFormat.TOSERIALIZEABLEDATE); works correctly in SmartGWT 4.0.
dateTimeItem.setDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE); did not provide required behavior even in 4.0, probably due to a default system wide format setting.
You should be able to use a value formatter as a workaround in 3.0.
dateTimeItem.setEditorValueFormatter(new FormItemValueFormatter() {
public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
if (value != null && value instanceof Date) {
return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format((Date) value);
}
return null;
}
});
Check DateItem.setEditorValueFormatter as you might have to set input format, etc. as well.
hi use the following code in your dateitem timeSheetDate.setShowPickerTimeItem(true); timeSheetDate.setTimeFormatter(TimeDisplayFormat.TOSHORTTIME); and also you can use timeSheetDate.setTimeFormatter(TimeDisplayFormat.TOTIME);

Resources