I am creating automated tests using appium to test an android app. The issue that I am facing right now, is that I cannot select a checkbox, because the checkbox contains linked text.
I am using the following code to get checkbox element and click it -
WebElement termsAndConditionsCheckbox = (new WebDriverWait(driver, 60)).until(ExpectedConditions.presenceOfElementLocated(By.id(baseTest.getAndroidElementId("checkbox_terms_and_conditions"))));
termsAndConditionsCheckbox.click();
In app code, the checkbox's text is set as follows -
mCheckboxTermsAndConditions.setText(Html.fromHtml(mSignUpAcceptTermsAndConditions));
mCheckboxTermsAndConditions.setMovementMethod(LinkMovementMethod.getInstance());
From debugging options on android device, I turned on the options to see pointer location of click event, and I see the appium clicks at the center of the checkbox (box + text), and unfortunately, that point contains a linked text, so the webview is launched, as opposed to "checking" the checkbox
I do not see a custom click() in appium, which would allow me to check the checkbox.
Would appreciate any ideas / help.
You can use find element By.className instead of By.id.
So for multiple such elements you can have them referenced with index (in this case 0), for example.
WebElement submit = (WebElement) driver.findElements(By.className(RADIO_BUTTON)).get(0);
submit.click();
Hoping this helps.
In this case, Instead of clicking on the checkbox directly..first get the location of checkbox and adjust the location by adding / subtracting some pixels so that it will always click on the exactly on the checkbox and not in the centre of the whole checkbox element.
You can use below code snippet :
WebElement element =driver.findelement(By.xpath("YourXpath"));
Point p=element.getLocation();
driver.tap(1, p.getX()+10, p.getY()+10, 1);
Related
Android has a technique where you can turn text into a button. You set the element to clickable, and then define an onClick() method for it.
On the Appium side, what I'm seeing is that the text for the element ends with an "#" character. For example from "UI Automator Viewer" :
(2) TextView: Purchase an item # [69,1038][1011,1110]
The '#' is displayed as an arrow symbol on the actual phone, and clicking on the arrow, and only the arrow, will take you to a different dialog (one to make a purchase in this case). Manually clicking on the text itself does not move the app to the dialog. Only clicking on the arrow works.
My Python code looks like:
self.driver.find_element_by_id("com.mycompany.project:id/make_a_purchase_text").click()
The click() method does not take me to the correct dialog. In fact, nothing apparent happens at all. I am click()ing on a lot of elements that are buttons in order to get to this point, so I know my setup is good. Is there any support at all in Appium for this sort of control?
I'm not sure whether this is the best way of doing it. To me it seems that selenium WebElement cannot detect the additional properties given to a TextView or a UIAStaticText. So when we assign a click property the base class behind the element cannot do the click event.
So as a workaround i sent a touch event to the required x,y location
driver.executeScript("mobile: tap", new HashMap<String, Double>() {
{
put("tapCount", 1d);
put("touchCount", 1d);
put("duration", 0.52478515625);
put("x", 127d);
put("y", 571d);
}
});
We are trying to write a test for an Native Android App and this has been driving me nuts.
solo.enterText(6, "100");
solo.enterText(7, "200");
solo.enterText(8, "300");
solo.enterText(9, "400");
all work fine, but once the index goes over 10 it fails to find any of the fields.
solo.enterText(10, "500");
solo.enterText(11, "600");
It also seems a little crazy to be counting the text fields and from within UIAutomator Viewer it does not seem to provide the true index number.
Is there a way to select the text field by resource id or the field name instead of the index number?
thanks for your help
Try this:
EditText editText
=(EditText)getActivity().findViewById(R.id.editText);
mSolo.enterText(editText,"500");
using R file and id resourse should be easier to test editText
My guess is that if you look at the screen you will only be able to see 10 edit text boxes and the edit texts with index 10+ are off the screen and inside a list view so they do not actually exist to robotium, you will need to scroll before you can input text but then the indexs will be off so you will have to compensate. The alternative is to find the edit texts by a different means like id or a tag or to find them as a child of the listview row that they are in.
If you can confirm it is because its in a list view i can find some code to help you.
I just downloaded AOSP and modified TextView for my purpose.
I have added a LongClick Listener to the TextView, which shows a simple Toast.
Since I modified the Android framework, it is reflected into all the apps and entire Android OS.
I have now run into a weird issue where the TextView is getting focus in some places and other underlying widgets are not getting any focus. This is creating lot of issues.
For eg: In Settings app, The 'Wi-Fi' text is receiving focus, but I cannot enter the wi-fi settings unless I click in any empty area in the Wi-Fi list item.
(I hope am clear!)
Another example: I am unable to select the Radio Button just because the text corresponding to Radio Button receives focus.
So my question is:
Is there any way I can make TextView non-focusable but receive Long Click events?
Is there any way I can pass the focus down to the parent layout?
Any other way you can suggest?
(PS: Please do not say what I am doing is right or wrong. It's just a feasibility test for what I am trying to achieve.)
A view does have the attributes "focusable" and "longClickable". Have you tried a combination of these?
I have a EditBox, and on right side of this EditBox I wan't to put a Button representing "Get My Position".
User clicks on this button, and my application get his position and fills EditBox with it.
I found a Compass and added on a ImageButton, but I don't know if this really represent the idea.
Anyone knows a better button to represent "Get My Position"?
Thanks
Your Button looks ok, and will be recognized by most users. If you want to get the System-default (the picture of the Drawalbe may differ on roms from HTC, Samsung Motorola etc) you can get it with
getResources.getDrawable(android.R.drawable.ic_menu_location)
Always check for non-Null here. You can download the standart Android location Button here, (ic_menu_location), as a fallback, if the getDrawable() call fails
I used a 'globe' in my application. If the EditBox is blank until the user requests their location, why not use the put some default text inside it requesting the user to click the button?
I like to recreate the behaviour of the textview containing the message of a user in the g+-app in my android project. To be exact:
- on click on a link the link is visually selected (blue selector) and will open up in the browser
- on click on normal text the whole list item is selected
The main problem I have, is, that every approach I tried to make links clickable (via xml and autolink=web, or in code) ends up, that the link opens up in a browser on click, but when I touch normal text in this textview the item is not selected (no selector is visible).
I read many threads about this issue, but all the solutions, like add setFocusable(false), etc. doesn't work for me.
So I want to ask, if there is any tutorial, how to or example, where I can see how this things work, or do you have any idea how I can get it to work?
Thanks! :)
if you have email id in textview use below code..
TextView email = (TextView)findViewById(R.id.TextView04);
email.setText("sasd asd#gmai.com sadasd");
email.setLinkTextColor(Color.WHITE);
Linkify.addLinks(email,Linkify.EMAIL_ADDRESSES);
if you have url in textview use below code...
TextView tv = (TextView)findViewById(R.id.TextView04);
tv.setText("sasd https://asd.com sadasd");
tv.setLinkTextColor(Color.WHITE);
Linkify.addLinks(tv,Linkify.WEB_URLS);