Appium on Android – sendkeys to EditText also type the default text

I'm trying to use appium for Android for WordPress mobile( https://github.com/wordpress-mobile/WordPress-Android )Write some automated tests

The first thing I have to do is to enter my user name in the main login interface so that I can log in to my WordPress website. I encountered the problem of sendkeys in the "user name" field

The following is how elements are displayed in the uiautomatorviewer:

This is what I have tried so far:

List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
WebElement login = textFieldsList.get(0);       
login.sendKeys("username");

And:

driver.findElementsByClassName("android.widget.EditText").get(0).sendKeys("username");

And:

driver.findElement(By.xpath("//android.widget.EditText[@text='Editing. Username or email. ']")).sendKeys("username");

Try to send "user name" as all 3 versions of the user name. When I run the test, what I actually type in this field is: "edit. User name or email. User name"

Therefore, it seems that the placeholder text is retained and my user name is added

Please note that when I use appium to send the user name, the added text is not there at first (see screenshot), but in the UI tree view, it seems to be the text in EditText. When appium runs the test, it actually writes the "edit. User name or email" text before adding my own user name

I have also tried, as suggested in one of the answers, to raise another question here: appium: clear a field the following code, where sendkeyevent (67) should clear the field:

List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
WebElement login = textFieldsList.get(0);
login.click();
driver.sendKeyEvent(67);
login.sendKeys("username");

Using. Clear() to crash, I noticed that others suggested avoiding it as much as possible

Of course, if I try to do this manually, placeholder text will not be added. I just type to add a user name in the field

I can also use the driver. Sendkeyevent() function and send one of my characters, but I want to send a user name as a parameter and can type any user name in the field

Because every time I try to enter a user name, I enter additional text. To solve this problem, I must first enter "user name" – in the application, the actual text entered is "edit. User name or email. User name" – and then move the cursor to stay in the word "username" Go ahead and start deleting the rest - but it's very slow. Here's the code that works this way:

        String setUsername = "username";
        login.click();
        login.sendKeys(setUsername);

        // hack to delete extra text that gets typed
        int stringLength = login.getText().length() - setUsername.length();
        for (int i = 0; i < setUsername.length(); i++) {
            driver.sendKeyEvent(21); //KEYCODE_DPAD_LEFT
        }
        for (int i = 0; i < stringLength; i++) {
            driver.sendKeyEvent(67); // "KEYCODE_DEL
        }

What did I miss? Any help would be appreciated. I try to understand why additional text is entered

resolvent:

After a lot of searching, I found that this is really an error in appium V 1.2.2:

https://discuss.appium.io/t/android-appium-1-2-2-sendkeys-issue-with-hinted-edit-text/309

Hopefully, as stated there, it will be fixed in version 1.2.3

Thank you for your help!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>