I am a developer using Appium to drive automated testing in an iOS app. We have been tapping into the accessibilityLabels to test, however the accessibilityLabels and actual text of the label is not always the same.
We would like to access the actual text attribute of the element to verify that it is correct. It would be great if we could tap into the size and location of the iOS element as well. Any help with this would be greatly appreciated.
I’ll start the answer and maybe someone will complete it!
As far as I know in ios you have element.text and element.name and the first should be the value of the element and the second the accessibility label. p.e.
TouchAction elementTap = new TouchAction(driver).tap(positionX,positionY);
elementTap.perform();
Note: surely I have typos on above code. I tried to write it in java, but I’m using ruby. Also you should not call getLocation and getSize so often, call it once and save the array results and the those variables, in order to decrease the calls to appium.
Can you explain more about the first_tag function? Do you mean first_ele? Because looking in the Appium documentation I see a first_ele function, but not a first_tag function.
Also, how do you recommend we test that this works? We are writing tests in a ruby file, but it looks like we only have access to the Selenium Web Driver Element functions. How do we access the Appium library functions from this file?
my mistake, as you said I mean first_ele, but that its a random example to gather one element, you can use button, text, find_element, etc…
You are testing with arc only? Or you already using cucumber or rspec?
I’m initializing my driver this way:
require 'rspec/expectations'
require 'appium_lib'
require 'cucumber/ast'
class AppiumWorld
end
caps = Appium.load_appium_txt file: File.expand_path('./', __FILE__), verbose: true
Appium::Driver.new(caps)
Appium.promote_appium_methods AppiumWorld
World do
AppiumWorld.new
end
Before do
$driver.start_driver
end
After do
$driver.driver_quit
end
sorry to say you are not right. Whats on the link you post is:
To find by text we can use the text command.
» text(‘API Demos’)
Selenium::WebDriver::Element:0x7f5348cbb3447ff2 id=“1”
The text command will look for any text on screen.
This looks for the text ‘API Demos’ and return the element where it founds it. In this case, if there is more than one, this command will return the first it finds.
To get the text from an element, as far as I know its:
element.text
in the above case
» text(‘API Demos’)
Selenium::WebDriver::Element:0x7f5348cbb3447ff2 id=“1”
» text(‘API Demos’).text
“Check out the API Demos”
Secondarily is there a reason why you are using the accessibilityLabels rather than accessibilityIdentifiers? I think that accessibilityLabels are specifically intended to be used by iOS for assistive functions, whereas accessibilityIdentifiers are for UIAutomation. Since assistive functions will be looking to read out the labels on each UI Element it would make sense for the system to conceal the text being visually presented on an element if a different accessibilityLabel has been set.