Example usage for org.openqa.selenium.interactions KeyInput createKeyDown

List of usage examples for org.openqa.selenium.interactions KeyInput createKeyDown

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions KeyInput createKeyDown.

Prototype

public Interaction createKeyDown(int codePoint) 

Source Link

Usage

From source file:io.appium.java_client.remote.AppiumW3CHttpCommandCodec.java

License:Apache License

@Override
protected Map<String, ?> amendParameters(String name, Map<String, ?> parameters) {
    // This blocks parent constructor from undesirable parameters amending
    switch (name) {
    case SEND_KEYS_TO_ACTIVE_ELEMENT:
        Object rawValue = parameters.get("value");
        //noinspection unchecked
        Stream<CharSequence> source = (rawValue instanceof Collection)
                ? ((Collection<CharSequence>) rawValue).stream()
                : Stream.of((CharSequence[]) rawValue);
        String text = source.flatMap(Stream::of).collect(Collectors.joining());

        final KeyInput keyboard = new KeyInput("keyboard");
        Sequence sequence = new Sequence(keyboard, 0);
        for (int i = 0; i < text.length(); ++i) {
            sequence.addAction(keyboard.createKeyDown(text.charAt(i)))
                    .addAction(keyboard.createKeyUp(text.charAt(i)));
        }//  w w  w.  j  a v a 2s . c o m
        return ImmutableMap.<String, Object>builder().put("actions", ImmutableList.of(sequence.toJson()))
                .build();
    case SEND_KEYS_TO_ELEMENT:
    case SET_TIMEOUT:
        return super.amendParameters(name, parameters);
    default:
        return parameters;
    }
}