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")
Related
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
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
I am a litte new in iOS UITest so apologises if something does not make sense.
I am trying to assert if a staticText is visible but it always returns false despite being shown.
The Screen looks like this:
The test function code looks like this:
func verifyBlockedAccountsEmptyState() {
print(profileListScreen.app.navigationBars["Blocked Accounts"].waitForExistence(timeout: 5))
print(profileListScreen.app.staticTexts.element.label)
print(profileListScreen.app.staticTexts["No blocked accounts"].waitForExistence(timeout: 5))
var elementLabels = [String]()
for i in 0..<profileListScreen.app.staticTexts.count {
elementLabels.append (profileListScreen.app.staticTexts.element(boundBy: i).label)
}
print("staticTexts -> ", elementLabels)
}
And the output:
true
12:25 PM
false
staticTexts -> ["12:25 PM"]
Any idea?
Thank you
EDIT
If I try to record the XCUIElement I get the following error:
Timestamped Event Matching Error: Failed to find matching element
A problem may be caused by using the wrong element type.
You probably should add a breakpoint and inspect this screen with lldb.
Type po print(app.debugDescription) to print the whole hierarchy of elements and their actual types.
It sounds like you should be assigning an AccessiblityId to part of the view you are interested in. You can see what's available in a given view by getting the container XCUIElement's debugDescription.
I am developing an iOs application with Swift and a total novice in application development. I use SwiftDate external library to deal with dates. SwiftDate is installed with CocoaPods and it is imported correctly in the project.
But I can't figure out why I get this error when I compile my project :
Extraneous argument label 'localeID' in call
For this code :
let now = NSDate()
let nowHere = now.toString() // E.g. 21-Dec-15 12:00 CET
let nowInFrench = now.inRegion(localeID: "fr_FR").toString()
I understand that's because the parameters are not formatted correctly, but this an exemple from the documentation so I am a little bit lost for this problem.
Thank's.
As Oliver mentioned, the first problem is the argument label in
let nowInFrench = now.inRegion(localeID: "fr_FR").toString()
to fix your
Extraneous argument label 'localeID' in call
error write it like this
let nowInFrench = now.inRegion("fr_FR").toString()
then you will come to the
Cannot convert value of type string to expect argument type Region
Error. This means you cannot simply give the function inRegion a String object. It wants a Region objects. The documentation says use create a region
let paris = DateRegion(timeZoneID: "CEST", localeID: "fr_FR")
let nowInFrench = now.inRegion(paris).toString()
The error is being flagged up because for the first argument in a function the label doesn't need to be written, only the ones after that.
If you just write:
let nowInFrench = now.inRegion("fr_FR").toString()
The error should go away.
I don't know why the example is written that way, maybe just for clarity.
Edit: having looked at the documentation I do think they have just included the labels to be clear as to what type they are using as an argument.
I understand how I could, for example look at one element in a table, but what's the correct way to simply iterate through all the elements, however many are found, to for example tap on them?
let indexFromTheQuery = tables.staticTexts.elementBoundByIndex(2)
Okay I succeeded in figuring out the simple syntax. I have just started working with Swift and so it took me sleeping on it to think of the answer.
This code works:
var elementLabels = [String]()
for i in 0..<tables.staticTexts.count {
elementLabels.append (tables.staticTexts.elementBoundByIndex(i).label)
}
print (elementLabels)
My guess is the answer is there is no way to do so.
The reason is because of my experience with one of the critical iOS components while making a number of UI tests: UIDatePicker.
If you record a test where you get the page up and then you spin the picker, you will notice that the commands are all non-specific and are screen related. In the case of the picker, however, community requests resulted in the addition of a method for doing tests: How to select a picker view item in an iOS UI test in Xcode?.
Maybe you can add a helper method to whatever controller contains this table. Also, keep in mind that you can easily add methods without polluting the class interface by defining them as extensions that are in test scope only.
For Xcode 11.2.1, SwiftUI and swift 5 based app, the following code works for testing a list, each element in this case appears as a button in the test code. The table is set up like this (for each row) :
NavigationLink(destination: TopicDetail(name: "Topic name", longDesc: "A description")) {
TopicRow(thisTopic: top).accessibility(identifier: "newTopicRow_\(top.name!)")
}
Then I catch the members of the table by getting the buttons into an array:
let myTable = app.tables.matching(identifier: "newTopicTable")
var elementLabels = [String]()
for i in 0..<myTable.buttons.count {
elementLabels.append (tablesQuery.buttons.element(boundBy: i).label)
}
print (elementLabels)
Finally, I deleted each member of the table by selecting the detail view where I have a delete button, again with
.accessibility(identifier: "deleteTopic"
I wanted to delete all members of the table:
for topicLabel in elementLabels {
let myButton = app.buttons[topicLabel]
myButton.firstMatch.tap()
app.buttons["deleteTopic"].tap()
}