Android Native:Appium.1.2.4.1: Couldn't delete textfield with gravity:center

Hi!

I have an EditText field it has an android:gravity=“center” attribute and a default value of “https://”.

When I try to clear this textfield:As I see the Appium clicks into the textfield and checks if it has any characters on the left and if has it removes those. Then clicks again and checks again then delete and so on. On the last time it clicks in it findes no character on the left so the textfield is empty for the Appium. At this point there is still a “/” left so my test fails because I couldn’t write the expected URL into the field.

Any advice?
Thanks in Advance!

@stsatlantis
Can you provide Appium logs… what version of Appium server are yo using??

I’m familiar with the system. Log won’t provide any further information and the server version is in the title: 1.2.4.1. I’m thinking about to change the way how webelement.clear() works. My solution would be clicking on the very end of the textfield and then try to clear / delete the content of it.

My bad, I didn’t notice it :smile:
The solution you are saying looks promising, i tried it myself when the clear method had problems before in the previous release.

Do give it a try and let us know…

I have to correct my self. As it seems to me it when you choose and element with findElementBy… method you near to the left edge of the textfield.

Try to tap at the element’s end position by using the function:

tap(int fingers, int x, int y, int duration)

then send a delete key event to delete the text from the textfield.

1 Like

Thanks I’ve found a way to solve my problem but not so nice.

I wrote a method which looks like this:

public class ExtendedAndroidDriver extends AndroidDriver {

public ExtendedAndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
	super(remoteAddress, desiredCapabilities);
}

public void clearTextFieldForMypurpose(WebElement webelement) {
	Dimension d = webelement.getSize();
	Point p = webelement.getLocation();
	int length = webelement.getText().length();
	Point click = new Point(p.x + d.width - 10, p.y + d.height / 2);
	tap(1, click.x, click.y, 10);
	for (int i = 0; i <= length; i++) {
		sendKeyEvent(AndroidKeyCode.DEL);
	}
}

Sending more DEL-key just in case :slight_smile:

I hope this will help someone :slight_smile:

2 Likes

By default text do you mean using android:text='https://', or something else? I’m trying to reproduce, unsuccessfully.

The logs really would be of help, too.

Yes, by default I mean android:text=‘https://’.
I cannot provide any log right now, but I can describe what I’ve seen:
(Showing of tap and position of the cursor is enabled on the device)

The test case is to send empty URL to the server.
During the test it’s been clicked into the textview it was on the left side but it jumped into the middle of the view and deleted the “http”, then tried again and delted the " : ", then the “/” and there was one “/” left but then the cursor was on the left side of the last “/” and the form’s been sent and returned with wrong error message (“Malformated URL” instead of “Empty URL”) every single time and it’s been right since I could see the “/” left on the screen. Because of this failure the next test case (wich was the correct URL) failed, too.

The code I use:

WebElement element= driver.findElementByAccessibilityId(“URLfield”);
element.clear();
element.send();
element.clear();
element.sendKeys(“workingURL”);

@stsatlantis
Where do you declare x and y?