无法在Appium Android Automation中清除TextField

时间:2019-12-10 13:06:32

标签: appium-android

我使用了以下代码:

web.sendKeys(Keys.chord(Keys.CONTROL,"a")); 
web.sendKeys(Keys.BACK_SPACE);

此方法几乎起作用,首先清除,然后输入字母a,不知道y,我尝试了element.sendKeys(Keys.Delete);,但仍然没有运气,该方法执行后附带的屏幕。

enter image description here

2 个答案:

答案 0 :(得分:0)

清除功能应提供您想要的内容:

@Override

public void onReceive(Context context, Intent intent) {

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent repeating_intent = new Intent(context, Reapting_activity.class);

    repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, repeating_intent, PendingIntent.FLAG_UPDATE_CURRENT);


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_DEFAULT);

        notificationChannel.setDescription("Channel description");
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
        notificationChannel.enableVibration(true);
        notificationChannel.setSound (Uri.parse ( "android.resource://com.mga5.almoshfwithnavigtiondrawer/raw/praymohamed" ),null  );
        notificationManager.createNotificationChannel(notificationChannel);
    }
    Calendar c = Calendar.getInstance();
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);

    if (Calendar.FRIDAY== dayOfWeek) {


        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);


        notificationBuilder.setAutoCancel(true)
                .setSound ( Uri.parse ( "android.resource://com.mga5.buttontocount/raw/praymohamed" ) )
                .setContentIntent(pendingIntent)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ic_book)
                .setTicker("السلام عليكم")
                .setContentTitle("صلى على محمد")
                .setContentText("اللهم صلى و سلم على سيدنا محمد")
                .setContentInfo("Info");
        notificationManager.notify(1, notificationBuilder.build());

    }else {

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);


        notificationBuilder.setAutoCancel(true)
                .setSound ( Uri.parse ( "android.resource://com.mga5.buttontocount/raw/praymohamed" ) )
                .setContentIntent(pendingIntent)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ic_book)
                .setTicker("السلام عليكم")
                .setContentTitle("لا تنسي ذكر الله")
                .setContentText("لا إله إلا الله")
                .setContentInfo("Info");

        notificationManager.notify(1, notificationBuilder.build());

    }






}

与此相关的文档可以在the official Appium documentation中找到。

答案 1 :(得分:0)

element.clear()可以使用,但是如果您实际上需要删除某些内容,则可以使用除

之外的所有内容

web.sendKeys(Keys.chord(Keys.CONTROL,"a")); 
web.sendKeys(Keys.BACKSPACE);

BACKSPACE中没有_

请记住,如果要在光标使用Keys.BACKSPACE之前删除字符,要在光标使用Keys.DELETE之后删除字符