Appium
Python
iOS
el.text and get_attribute('label') etc. all seem to pulling accessibility information. Is there a way to pull the actual text that is displayed on screen using Appium? I need to be able to pull for a given element.
It does not return visible text if you use .text
You need to ask the developer to add a new attribute in the iOS code with the actual mention of the original url text. Then you will be able to see the new attribute in the Appium element locator table. If this is not done there is no value in the appium element locator table to give you the visible text
You can use .text
element = driver.find_element_by_class_name("class_name").text
print(element)
it will return you text and verify f you required.
Try this one it will help you
element = driver.find_element_by_class_name("class_name").get_attribute('text')
print(element)
or
Second one - Give you exact text from android ui
element = driver.findElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.EditText\")").get_attribute('text')
print(element)
I am quite sure, that .text will give you the element's text when the element is visible.
Beware, Appium does give you an empty string here, if it deems the element not visible (out of screen- bounds or hidden or behind another element). If you need to get the text of elements which are not visible, you may try this one driver.find_element_by_class_name("class_name").get_attribute('textContent')
Related
This is image of android inspectorUnable to identify elements in Appium inspector instead of one element whole panel type of area is selecting when I click on menu I want to select on element from that menu which comes from left to right.
Please help me so that I can find a single element's xpath right now whole panel is getting selected in appium inspector. enter image description here this is on android.
Unfortunately it's not behaviour you can change in the Appium Inspector.
That doesn't mean it stops you from identifying elements. You can click on the XML tree and open and look manually for your elements. If you found the right element in the tree, then you can check out the properties and work out the right XPath.
After that you can test the XPath by using the selector tester in the top menu of the Inspector.
New edit:
Automating between Native and WebView can be read here on appium.io. The elements you find in the inspector are probably in the WebView and you must switch to this in order for Appium to reach the correct elements.
Step 1: Print out all possible views through - this way you can retrieve what views there are and switch between them if you are in the app. Within hybrid apps, there are different views and you need to enter the correct one first in order to automate elements.
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
}
driver.context(contextNames.toArray()[INDEX]);
Step 2: Print the page source to get a scope of all elements in the currenct view through driver.getPageSource(). If you do this for all views you can see the possibilities and elements you have.
Say I have a dialog box like this:
and I want to focus on title, then body and then each button one after another. I am able to focus on body using
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, dialog.bodyLabel);
but is there any way to define a set of elements we want to focus instead of a single one?
EDIT:
I have also tried to make a list of elements I want to focus on using this syntax:
dialog.accessibilityElements = #[dialog.titleLable, dialog.bodyLable, etc];
but it just reads the first element (in this case dialog.titleLable) and doesn't move to the next one. Any thoughts?
The default value is set to NO for all the elements.
set the isAccessibleElement to YES for the all individual elements in the dialog
and then you can do
dialog.accessibilityElements = #[dialog.titleLable, dialog.bodyLable];
so that voice over reads title label first and body label next.
I am working on iOS native app and when trying to read from tableView/tableCells I have a problem getting the updated values. At the first time i enter the page/screen I can see all cells. But , if i create an action that adds another cell to the table view when I try to get the list of cells I see an empty list.
Also, When i change a subelement in that cell I can't see the changed sub element both in inspector and in the code.
I tried switching to a different page and also changing tabs in that page and reread the table/cell and subelements but it didn't help.
I've had this issue before. There is no actual reload elements kind of function that I've seen. However a workaround I've found that works is to simply find an element that exists and it'll reload the elements after it does that.
For example:
yourMethodThatLoadsNewElements();
driver.findElementBy(pathToElementThatExistedBefore);
driver.findElementBy(pathToElementThatWasJustLoaded);
Is it possible to add a text link into a TextView? I want the link to perhaps behave like a button, where I can assign an action to it.
EDIT: When I say assign an action, I mean actually giving it something in the code. I'm wondering if it's possible to dynamically add a "button" into text that I can assign a coded action to.
Live scenario
Think of something like a dictionary app. Maybe the definition of one word uses another word that you might not know the definition of, so being able to click on that word to instantly search it rather than having to type it in would be a nice user friendly feature. It seems rather unlikely, though, I guess.
I would recommend using NIAttributedLabel from Nimbus, an open source iOS library. You can specify text ranges that are links, and you get delegate messages sent when a user taps on it.
Main Nimbus site: http://nimbuskit.info/
NIAttributedLabel docs: http://docs.nimbuskit.info/interface_n_i_attributed_label.html
in the inspector, go to the Text View Attributes tab then make sure "Detect Links" is checked.
Yes you can. Add the URL into the text view, then open up the Attributes Inspector. You will see an option in there to detect links.
I know of a way, but its a LOT of work. First, you have an NSAttributedString that you have the text view display. Second, attribute the range of text you want to be the button. Third, assign a tap gesture recognizer to the text view and in the method called by the recognizer, you'll use core text to determine if the tap happened over the range of text that represents the buttons.
Heres how youll use core text: create a framesetter with the attributed string. Create a frame from the framsetter with the shape of a square that is the frame of the text view, inset by the padding of the text view. The frame will allow you to get the y origins of every line in the text view and and once you know what line the tap happened on, you can use the line to then figure out exactly what character was tapped on that line by giving it an x offset. Once you know character index on the line, you can add it to the beginning of the range of the line and get the index of the character within the whole string. Then you can check if its within the range of the text that is your button. If it is, you can then call a method to simulate a target action type behavior.
Ive explained the process of how to accomplish this and specified what kinds of core text objects youll need, ill let you look up the specific api details:
https://developer.apple.com/library/mac/documentation/Carbon/Reference/CoreText_Framework_Ref/_index.html#//apple_ref/doc/uid/TP40005304
You can also use my objc core text wrapper:
https://github.com/mysterioustrousers/MYSCoreText
What about CoreText? It Can draw many kinds of Text .
The form window(chat window) that i am creating for a lan messenger is similar to the one in google talk with two textboxes. What i need to do is to transfer characters typed in the lower textbox(textbox2) to the upper textbox(textbox1 which is read-only) when i click the submit button without showing that textbox1 is read-only because the characters are appearing in grey.please help with code if possible.
Use a label for this instead of a textbox. If the only thing it is doing is display the characters and not a direct edit, you won't lose any functionality and the text would not be greyed out...
If you're going to use a Texbox, set it to Locked. That shouldn't gray the characters out. Otherwise in KeyDown/KeyUp events, set the e.Handled property to true (which will tell the box that you want to handle the input yourself and don't want the message to filter down).
That oughta do it for you.