How to use Appium to select the elements from a searchview dropdownlist? - appium

As you can see in this picture, I can't locate the Id or XPath of the details I want to click. I'm using AndroidDriver.
I had tried the following codes:
AndroidElement searchView = androidDriver.FindElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Tribology Testing\"));");
but I still can't get the Tribology Testing being select.

We cannot help you to come up with the correct element locator without seeing your application layout, screenshot doesn't help at all.
You can see the layout by invoking AndroidDriver.getPageSource() function - it will print all the UI hierarchy of the current screen and you will be able to create the corresponding selector.
Another options are:
Android Device Monitor (part of Android SDK)
Layout Inspector (part of Android Studio)
XPath Feature of the Appium Studio

Related

Get all elements in the view of iphone app using xcode

I am trying to take screenshot of every screen during iphone app automation on a simulator. Along with the screenshot I also want to extract all strings in the that particular view before taking a screenshot using xcode. Is there a way to do that? Purpose is to send these screenshots and strings for validation to another tool.
This can be done using Web Driver Agent(WDA) provided by facebook. It does provide all the functionalities you need for your app.
Here is link to github repo for it:
https://github.com/facebook/WebDriverAgent
Please have a look at it. It might help you achieving your goal.
If you are using the XCUITest framework for your automation, you can use XCUIScreen.main.screenshot() to get a screenshot of the current state.
To fetch all text currently on screen you can use XCUIApplication().descendants(matching: .textField) or .buttons or .any or whatever you expect to be on the screen, and extract the text from the element
let descendants = XCUIApplication().descendants(matching: .textField)
foreach descendant in descendants { descendant.label /*do something*/ }
You need to set an Accessibility Identifier on the view elements for this to work.

Appium fails to locate element off-screen using UiSelector

I'm starting to automate a test suite for a mobile app coded in NativeScript (it used to be a hybrid Cordova app) and it's proving difficult to locate some elements.
I'm trying to locate a TextView widget that's outside of the visible screen space (AKA viewport) using UiSelector:
#AndroidFindBy(uiAutomator = "new UiSelector().textContains(\"CFT\")")
private MobileElement labelCFT;
When I try to interact with such element, the result is the following message:
org.openqa.selenium.NoSuchElementException: Can't locate an element
by this strategy: By.chained({By.AndroidUIAutomator:
new UiSelector().textContains("CFT")})
The logic conclusion would be that the element does not exist or my locator strategy is faulty. But here is the thing, when I change the text to find for that of an element that's inside the visible space/viewport, the locator works flawlessly. Example:
#AndroidFindBy(uiAutomator = "new UiSelector().textContains(\"loans\")")
private MobileElement labelCFT;
And then:
public void whatText() {
System.out.println("Text of the label: " + labelCFT.getText());
}
I get the correct "Text of the label: These are your loans".
Apparently, it's a limitation of the UiSelector or at least the way Appium works with it.
The only option I imagine is to scroll the whole screen and then trigger #AndroidFindBy, then repeat until there's no scroll left.
Is this suppose to be how UiSelector and textContains() work?
Is it another solution for this?
Many thanks.
I have faced similar type of problems in automation. The only way around I found was to scroll up or down till the element is visible on screen and then access the element by "name". you can use the following command for scrolling.
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Your Element\"));");
After your desired element is visible on the screen you can access that element easily.
Thanks
In Android App you can only click or do any actions on the elements which are visible on the screen if you want to perform any actions on element which are not visible you can use touch action method where you need to specify x and y cordinated i think this might help you in my case this works
TouchAction ta = new TouchAction(driver);
ta.press(PointOption.point(207, 582)).moveTo(PointOption.point(8, -360)).release().perform();

Unable to Click via xpath,classname,location or index

I am working to automate an android app which have some screen of webview too. I am unable to click the right element through xpath class, with index or even with giving name text.
If you see these screenshots it is visible that when I inspect element i get link to somewhere else. i tried using getlocation and then pass it for click but it also getting me wrong click.
I tried touchaction class methods but they are not working. My code get pass through appium but the methods tap or press nothing.
I tried this way too but no luck.
WebElement Quiz1 = (new WebDriverWait(driver , 20))
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.view.View[contains(#content-desc,'Die Wish App')]")));
Quiz1.click();
Any help would be appreciated. Also how can I use webview rather than webelement? and which one is preferable?
You can click on the element which you have highlighted in the screenshot.Below is the locator to identify that element
By.accessibilityId("Die Wish App")

How can you see the XCUIElement tree?

Background:
I'm experimenting with ui level testing in iOS 9.0 with XCode GM.
Question:
Is there a command in XCode GM that will allow you to see a 'tree' of accessible elements and their relationships? Something similar to the 'page' command in Appium?
Ideally I would be able to run a command in the debugger that would give me a list of elements available for selection/manipulation. Currently you can use debugDescription on a single XCUIElement but that only gives you info for that element.
Set a break point where you would like to see the tree... in the debugger type:
po print(XCUIApplication().debugDescription)
That prints out everything XCUITesting has access to. You can also just throw that in to your test:
func testTreeExample() {
XCUIApplication().buttons["login"].tap()
print(XCUIApplication().debugDescription)
XCUIApplication().buttons["next"].tap()
print(XCUIApplication().debugDescription)
}
Thta way if you are having trouble finding something you can have it automatically print out what the app sees right after you do something.
This isn't exactly what you're asking for, but Xcode’s Accessibility Inspector makes it much easier to look at your view hierarchy in terms of what elements are accessible via Identifiers. (N.B. It's not the "Label" in IB's Accessibility panel that matters, it's the "Identifier" field.):
In Xcode 7.2, open Xcode->Open Developer Tool->Accessibility Inspector. (You may need to give the app permission to run in System Preferences.) Then launch your iOS app from Xcode and hover over any UI element in the SIMULATOR. You’ll see comprehensive information about the element type, description, hierarchy, etc.
Anytime you record UI actions and the output doesn't look right, use the tool to figure out what accessibility descriptions need to be added, changed, or removed. (I spent a couple days trying to get a deeply embedded UISegmentedControl to change via the UI Test harness, and the problem became obvious once I figured out how to use the Accessibility Inspector tool.)
Thanks to the folks at shinobicontrols.com for the great tip!
I would suggest choosing from the menu bar: Debug > View Debugging > Capture View Hierarchy when running in debug. Not only do you a way of visually representing the views but also the left-side debug navigator shows the hierarchy. This may not be one-for-one with UI Testing's perspective but it can be very helpful. Hope that helps.
The way Appium does this is using Facebook WebdriverAgent.
As far as I can tell, the way they do it, essentially, is starting from the root application element and collecting information about each child, then recursing.
What about http://fbidb.io?
With idb ui describe-all command you get the accessibility information of all the elements on screen (not the entire app) https://fbidb.io/docs/commands#accessibility-info
Put a breakpoint in any of your tests then just do: po XCUIApplication() and that will print out the whole app's accessibility hierarchy in easy to read tree format.

How to click/tap on content drawn using core graphics in appium for iOS

I am new to Appium and use it for iOS native app automation.
Appium version : 1.2.0
Webdriver : Selenium
Testing framework : JUnit
Programming language : Java
I have an iOS application where the contents are drawn using Core Graphics. I need to click/tap on certain content(word) using Appium with the co-ordinates specified.
My question is, how can I tap on the content drawn using CG?
For example, how can I click on "Start" using Appium using co-ordinates where the origin is x=0, y=102 and size is height=305, width=320.
The content is present within this and must be scrolled for other contents.
I tried with .tap, .press of TouchAction(). The test case passed but it has not clicked.
Please help me solve this.
Thanks in advance.
This is the general gist of what you need to do to tap something. (My attempt at a Java translation of my python code)
WebElement application = driver.findElement(By.xpath("//UIAApplication[1]"))
Action action = TouchAction(driver)
action.tap(application, x, y, 1).perform()
When testing drawing/tapping code, I like to point it at a sample drawing app like this one and that lets me see exactly what's going on.

Resources