Appium, XCUITEST, and xpaths

How do I find elements by xpath using the new driver?

currently on 1.5.3 we are using the UIA xpaths -> //UIAApplication[1]/UIAWindow[2]/UIAKeyboard[1]

but these don’t work with xcuitest as the driver. How do I locate by xpath on this new driver on 1.6.0-beta2?

I also want to know how to locate elements in Webview with new xcuitest if it supports hybrid app.

all your elements renamed to others:

UIAApplication → XCUIElementTypeApplication
UIAWindow → XCUIElementTypeWindow
UIAKeyboard → XCUIElementTypeKeyboard

to see how it look like try following on needed screen:

System.out.println(driver.getPageSource());

Im not able to call getpagesource. Im using Appium_lib on ruby and driver doesn’t seem to have that method?

In ruby I believe it is driver.page_source

getting a no method error despite it being present in the webdriver bridge

undefined method 'page_source' for #<Appium::Driver:0x007fd738cb5dd8> (NoMethodError)

Hi pmck91,

I did get page_source to work, however page_source is actually a WebDriver command. In order to use it in a Ruby Appium test, you need to cast an instance of your driver as a webdriver driver.

For example when declaring your appium driver you would need to do something like this:
@driver = Appium::Driver.new(caps)
@seleneium_driver = @driver.start_driver
Appium.promote_appium_methods Object

In your method your would call something like:
test_page_source = @selenium_driver.page_source

I tested similar code to this in my Ruby project and was able to get the page source of the web page returned.

Hope that helps!

I think by this time, you got the answer on how to locate xpath with appium new xcuitest driver. But still I am posting the answer

Option 1:
Download Mykola:

Usage
Execute your iOS test using Appium (by default it is expected to listen on http://localhost:4723) and set a breakpoint where you want to investigate the UI tree. Open/refresh iOS Inspector.html web page in your favourite web browser, wait for a while until the data is loaded and you are ready to go. The inspector currently supports showing of element attributes, element location by XPath and, naturally, two-way visual elements location using a screenshot and the UI tree.
Note: The Accessibility Id property can be presented as @name attribute in XPath expessions.

Customizations
Change the default Appium server address if needed inside inspector.js file, APPIUM_ROOT constant.

Option 2:
System.out.println(driver.getPageSource()); - By this you can get the page source and you can extract the xpath the page source

@SireeshaSimakurthy i downloaded that however I noticed that on my simulator it is not identifying the elements. I can still highlight the tree on the right to get the xpath of an element…but when I run the test using that xpath it is never identifying that element?

Thanks.