iOS: How to get the text of the label in iOS app?

1,239 views
Skip to first unread message

SF QA

unread,
May 23, 2014, 4:43:56 AM5/23/14
to appium-...@googlegroups.com
I am trying to fetch the text of the label using xpath of that label.
WebElement element=wd.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[4]"));
String val=element.getText();

Every time i am getting null value as a result;

Is there any other way to fetch the text?

Isaac Murchie

unread,
May 23, 2014, 9:59:01 AM5/23/14
to SF QA, appium-...@googlegroups.com
Unfortunately, iOS has a bug in which the name of a label is always returned as it's text. You can set the name, but that doesn't work if it is dynamic at all. 

I've gotten around it by making my labels be read only text fields. 
--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Rameshwar Juptimath

unread,
May 23, 2014, 10:53:53 AM5/23/14
to appium-...@googlegroups.com
I don know if this works, but Try this:


WebElement element=wd.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[4]"));
String val=element..getAttribute("text");

ajeesh vl

unread,
May 25, 2014, 11:15:38 PM5/25/14
to appium-...@googlegroups.com, SF QA
Hi Issac,

Try WebElement element=wd.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[4]"));
String val=element..getAttribute("label"); // for getting text from static text element

Also, if you want to get the value from a text box try
element.getAttribute("value");



On Friday, 23 May 2014 19:29:01 UTC+5:30, Isaac Murchie wrote:
Unfortunately, iOS has a bug in which the name of a label is always returned as it's text. You can set the name, but that doesn't work if it is dynamic at all. 

I've gotten around it by making my labels be read only text fields. 

On Friday, May 23, 2014, SF QA <shivang....@gmail.com> wrote:
I am trying to fetch the text of the label using xpath of that label.
WebElement element=wd.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[4]"));
String val=element.getText();

Every time i am getting null value as a result;

Is there any other way to fetch the text?

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discuss+unsubscribe@googlegroups.com.

SF QA

unread,
May 26, 2014, 1:31:38 AM5/26/14
to appium-...@googlegroups.com
Its working now using String val=element..getAttribute("label");
Reply all
Reply to author
Forward
0 new messages