Example usage for org.openqa.selenium WebElement sendKeys

List of usage examples for org.openqa.selenium WebElement sendKeys

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement sendKeys.

Prototype

void sendKeys(CharSequence... keysToSend);

Source Link

Document

Use this method to simulate typing into an element, which may set its value.

Usage

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebAutoComplete.java

License:Open Source License

/**
 * Mtodo generalizado para selecionar o valor da lista
 * /*  www  .jav a  2s .c  o  m*/
 * @param value Valor a ser informado no campo de texto do autocomplete
 */
protected void select(String value) {

    // Aguarda o primeiro elemento ser clicvel
    waitElement(0);

    List<WebElement> elements = getElements();
    if (elements.size() == 1 && getElementMap().locator().length == 1) {
        throw new BehaveException(
                message.getString("exception-autocomplete-missing-elements", "locator", "@ElementMap"));
    }

    WebElement element = elements.get(0);

    if (element.getTagName().equals("input") && element.getAttribute("type").equals("text")) {
        // Preenche o valor do Autocomplete
        element.clear();
        element.sendKeys(value);
    }

    /*
     *  Tempo do efeito de abertura das opes
     *  
     *  Obs: Utilizada API de Reflection para retrocompatibilidade
     *      com verses anteriores do DBehave (1.3.0 por exemplo) 
     */
    try {
        Method waitElementOnlyVisible = getClass().getMethod("waitElementOnlyVisible",
                new Class[] { Integer.class });
        try {
            waitElementOnlyVisible.invoke(this, new Object[] { 1 });
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (NoSuchMethodException e) {
        waitElement(1);
    }

    if (this.selectValue != null) {
        value = this.selectValue;
    }

    selectOnList(elements.get(1), value);
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebFileUpload.java

License:Open Source License

public void sendKeys(CharSequence... keysToSend) {
    WebElement input = this.getElements().get(0);
    input.sendKeys(keysToSend);
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java

License:Open Source License

public File saveScreenshotTo(String fileName, boolean generateSource) {
    File screenshotFile = new File(fileName);

    screenshotFile.getParentFile().mkdirs();

    driver.manage().window().maximize();

    File screenshot = null;//from   w w w.  j a  va2 s.  c o  m

    if (BehaveConfig.getRunner_screenShotZoomout() != 0) {
        WebElement html = driver.findElement(By.tagName("html"));

        for (int x = 0; x < BehaveConfig.getRunner_screenShotZoomout(); x++) {
            html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
        }

        screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        html.sendKeys(Keys.chord(Keys.CONTROL, "0"));
    } else {
        screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    }

    if (screenshot != null) {
        try {
            FileUtils.copyFile(screenshot, new File(screenshotFile.getAbsolutePath()));

            if (generateSource) {
                writeHtmlFile(screenshotFile.getAbsolutePath());
            }
        } catch (IOException e) {
            throw new BehaveException(message.getString("exception-save-screenshot"), e);
        }
    }

    return screenshotFile;
}

From source file:br.ufmg.dcc.saotome.beholder.selenium.WebElementAdapter.java

License:Apache License

@Override
public void sendKeys(final CharSequence... keysToSend) {
    (new StaleExceptionResolver<Object>() {

        @Override/*from   www .ja  v a2  s .c o m*/
        public Object execute(WebElement element) {
            element.sendKeys(keysToSend);
            return null;
        }
    }).waitForElement();
}

From source file:browsermator.com.DownArrowKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {/*  w  ww. ja va 2 s.  c om*/
        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.ARROW_DOWN);

        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }
}

From source file:browsermator.com.EnterKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {//from   w ww  . jav a  2 s  .  c o  m
        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.RETURN);

        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }

}

From source file:browsermator.com.EscapeKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {//w w w .ja  v  a 2s  .  co  m
        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.ESCAPE);

        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }

}

From source file:browsermator.com.LeftArrowKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {/*from   w ww .  j a  v a2  s. com*/
        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.ARROW_LEFT);

        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }
}

From source file:browsermator.com.RightArrowKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {//w  ww  .j av  a 2 s . co m
        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.ARROW_RIGHT);
        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }

}

From source file:browsermator.com.UpArrowKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {/*from  w w  w.  j av  a 2  s  . com*/

        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.ARROW_UP);
        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }

}