iOS Page Indicator Navigation

I’m new to Appium.

I’m trying to understand how to navigate a page indicator. Is it possible to call something equivalent to goToNextPage() or selectPage(1) in Appium? The closest thing I found was a precise tap. Also, the ruby output for a precise tap is;

Appium::TouchAction.new :x => 214, :y => 616, :fingers => 1, :tapCount => 1, :duration => 0.5

but when I use the recording in my .rb, I get the error:

...appium_lib-3.0.3/lib/appium_lib/device/touch_actions.rb:29:in `initialize': wrong number of arguments (1 for 0)

It replays fine in the Appium.app.

Hi Russ,

Your link is to a developer page. I don’t think that Appium has that low level of access. Instead, you should look for a button that the developer has linked to the underlying API.

You can just use a touch_action, but I think you’ll find that it will break when the developer(s) make any kind of UI change.

Thanks for your reply.

I got it working by changing the line to:

driver.execute_script 'mobile: tap', :x => 214, :y => 616, :fingers => 1, :tapCount => 1, :duration => 0.5

Is that the right way to make this work?

Page indicators are not like regular buttons, they are more like segmented controls. They don’t have just one tappable area, they have two. Can you tap an area specific to the bounds of the element? I would need to tap on the right half. The link I included was to the ui automation framework for page indicators.

Here’s a method I use to find the center of an element:

def element_center(element)
location = element.location;
log.info "location.x = " + location.x.to_s
log.info "location.y = " + location.y.to_s
log.info "location.x + element.size.width divided by 2 = " +
(location.x + (element.size.width/2)).to_s
log.info "location.y + element.size.height divided by 2 = " +
(location.y + (element.size.height/2)).to_s
location.x = location.x + element.size.width/2
location.y = location.y + element.size.height/2
location;
end

You’d need to adjust it a little to the right for your use. (this is in Ruby).

Seems awfully convoluted in my opinion. An easier solution exists.

iOS UIAutomation has a functionality for UIAPageIndicator elements, i.e goToNextPage() and goToPreviousPage(). (See link).

I am doing this by executing an Appium UIAutomation Script as follows.

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("UIATarget.localTarget().frontMostApp().mainWindow().pageIndicators()[0].goToNextPage()");
1 Like