Java Code Examples for org.openqa.selenium.WebElement.sendKeys()

The following are Jave code examples for showing how to use sendKeys() of the org.openqa.selenium.WebElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ServiceNow_Selenium   File: ServiceNow.java   View Source Code Vote up 6 votes
/**
 * Types into the search bar in the top right and searches.
 * 
 * @param content
 *            - The value to type into the search bar.
 */
public void searchFor(String content) {
	this.focusForm(false);
	WebElement mGTypeArea = _wait.until(ExpectedConditions.presenceOfElementLocated(By.name("sysparm_search")));
	if (!mGTypeArea.getClass().toString().contains("focus")) {
		WebElement magnifyingGlass = _wait
				.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[action='textsearch.do']")));
		magnifyingGlass.click();
	}
	if(!mGTypeArea.getAttribute("value").equalsIgnoreCase("")) {
		mGTypeArea.clear();
	}
	mGTypeArea.sendKeys(content);
	mGTypeArea.sendKeys(Keys.ENTER);
}
 
Example 2
Project: marathonv5   File: JButtonHtmlTest.java   View Source Code Vote up 6 votes
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("<html><center><b><u>D</u>isable</b><br><font color=#ffffdd>middle button</font>", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("<html><center><b><u>E</u>nable</b><br><font color=#ffffdd>middle button</font>", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
 
Example 3
Project: marathonv5   File: JButtonTest.java   View Source Code Vote up 6 votes
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("Disable middle button", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("Middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("Enable middle button", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
 
Example 4
Project: willtest   File: EventListenerExample.java   View Source Code Vote up 5 votes
@Test
public void testEventListenerWithError() {
    WebDriver webDriver = rule.getWebDriver();
    webDriver.get("https://github.com");
    WebElement searchInput = webDriver.findElement(By.cssSelector(".header-search-input"));
    searchInput.sendKeys("will", "test");
    searchInput.sendKeys(Keys.ENTER);
    String searchKeyword = webDriver.findElement(By.cssSelector(".header-search-input")).getAttribute("value");
    assertThat(searchKeyword, is("foooooo"));
}
 
Example 5
Project: SilkAppDriver   File: NotepadDemoTest.java   View Source Code Vote up 5 votes
@Test
public void testGetAttribute() {
	WebElement textField = driver.findElement(By.xpath("//TextField"));
	textField.sendKeys("hello");

	// TODO: Currently (Selenium 3.6) getAttribute delegates to
	// executeJavaScript with a complex script which we can't support.
	
	String enabled = textField.getAttribute("Enabled");
	// assertEquals("true", enabled);
	// assertEquals("Consolas", textField.getAttribute("Font"));
	// assertEquals("false", textField.getAttribute("IsPassword"));
	// assertEquals("MultiLine", textField.getAttribute("true"));
}
 
Example 6
Project: seleneasy   File: Seleneasy.java   View Source Code Vote up 5 votes
/**
 * Send keys with delay
 * @param element Element to send
 * @param message Message to put
 * @param delay Delay in ms
 */
public void sendKeysDelay(WebElement element, String message, long delay) {
    
    for (char c : message.toCharArray()) {
        element.sendKeys(String.valueOf(c));
        try {
            TimeUnit.MILLISECONDS.sleep(delay);
        } catch (InterruptedException e) {
            //its ok
        }
    }
    
}
 
Example 7
Project: ats-framework   File: RealHtmlElement.java   View Source Code Vote up 5 votes
/**
 * Simulate Tab key
 */
@Override
@PublicAtsApi
public void pressTabKey() {

    new RealHtmlElementState(this).waitToBecomeExisting();

    WebElement element = RealHtmlElementLocator.findElement(this);
    element.sendKeys(Keys.TAB);
}
 
Example 8
Project: marathonv5   File: JTableTest.java   View Source Code Vote up 5 votes
public void tableCellEditUneditable() throws Throwable {
    driver = new JavaDriver();
    try {
        WebElement cell = driver.findElement(By.cssSelector("table::mnth-cell(3,1)::editor"));
        cell.sendKeys("Hello World", Keys.ENTER);
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}
 
Example 9
Project: POM_HYBRID_FRAMEOWRK   File: WebTextbox.java   View Source Code Vote up 5 votes
public static void sendKeysNTimes(WebElement element, int numberOfTimes, Keys keyName) {
	try {
		for (int count = 1; count <= numberOfTimes; count++) {
			element.sendKeys(keyName);
		}
	} catch (Exception e) {
		System.out.println("Error occured while sending keys...\n" + e.getMessage());
	}
}
 
Example 10
Project: ohjelmistotuotanto2017   File: Stepdefs.java   View Source Code Vote up 5 votes
@When("^username \"([^\"]*)\" and password \"([^\"]*)\" are given$")
public void username_and_password_are_given(String username, String password) throws Throwable {
    WebElement element = driver.findElement(By.name("username"));
    element.sendKeys(username);
    element = driver.findElement(By.name("password"));
    element.sendKeys(password);
    element = driver.findElement(By.name("login"));
    element.submit();  
}
 
Example 11
Project: testing_security_development_enterprise_systems   File: HomePageObject.java   View Source Code Vote up 5 votes
public void changeData(String value){

        WebElement text = getDriver().findElement(By.id("form:text"));
        WebElement button = getDriver().findElement(By.id("form:modify"));

        text.clear();
        text.sendKeys(value);
        button.click();
        waitForPageToLoad();
    }
 
Example 12
Project: marathonv5   File: JTableColumnSelectionTest.java   View Source Code Vote up 5 votes
private void clickOnCol(WebElement table, int colNum) {
    // Index on the element is 1 based and index on the JTable is 0 based.
    // Hence adding 1 to the colNum
    WebElement col = table.findElement(By.cssSelector(".::mnth-cell(1," + (colNum + 1) + ")"));
    col.click();
    table.sendKeys(Keys.NULL);
}
 
Example 13
Project: NaukriSite   File: ProfilePage.java   View Source Code Vote up 4 votes
public void UpdateCV (String filePath) {
	
	WebElement viewProfile = driver.findElement (By.linkText ("View Profile"));
	
	Actions act = new Actions(driver);
	act.click (viewProfile).perform ();
	
	WebElement uploadLink = driver.findElement (By.id ("uploadLink"));
	act.click (uploadLink).perform ();
	
	WebElement attachCV = driver.findElement (By.id("attachCV"));
	attachCV.sendKeys (filePath);
	
	sleep();
	
	WebElement saveCV = driver.findElement (By.cssSelector("button.w85bt.fl"));
	act.click(saveCV).perform ();
	
	sleep();
}
 
Example 14
Project: testing_security_development_enterprise_systems   File: PageObject.java   View Source Code Vote up 4 votes
public void setText(String id, String text){
    WebElement element = driver.findElement(By.id(id));
    element.clear();
    element.sendKeys(text);
}
 
Example 15
Project: testing_security_development_enterprise_systems   File: PageObject.java   View Source Code Vote up 4 votes
public void setText(String id, String text){
    WebElement element = driver.findElement(By.id(id));
    element.clear();
    element.sendKeys(text);
}
 
Example 16
Project: tmply   File: TmplyPage.java   View Source Code Vote up 4 votes
public void setBucketName(String bucketName)
{
	WebElement bucketNameInput = getBucketNameInput();
	bucketNameInput.sendKeys(bucketName);
}
 
Example 17
Project: QA_Begin   File: TestContactDoq.java   View Source Code Vote up 4 votes
@Test
    public void cadastro() throws InterruptedException {

        WebDriverWait wait = new WebDriverWait(driver, 30);

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Name")));
        WebElement name = driver.findElement(By.id("Name"));
        name.sendKeys("Vitor Cardoso");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Email")));
        WebElement email = driver.findElement(By.id("Email"));
        email.sendKeys(("[email protected]"));

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Site")));
        WebElement site = driver.findElement(By.id("Site"));
        site.sendKeys("www.doqconsulting.com.br");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Subject")));
        WebElement assunto = driver.findElement(By.id("Subject"));
        assunto.sendKeys("Teste Selenium com assert");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Message")));
        WebElement message = driver.findElement(By.id("Message"));
        message.sendKeys
                ("Gostaria de saber mais sobre a DOQ Consulting e como podemos ajudá-lo? Envie sua mensagem pelo site ou em nossas redes sociais.");

        // SUBMIT AND ASSERT
        name.submit();
        String respname = name.getAttribute("value");
        Assert.assertEquals(respname,"Vitor Cardoso");

        email.submit();
        String resp = email.getAttribute("value");
        Assert.assertEquals(resp,"[email protected]");

        site.submit();
        String respsite = site.getAttribute("value");
        Assert.assertEquals(respsite,"www.doqconsulting.com.br");

        assunto.submit();
        String respassunto = assunto.getAttribute("value");
        Assert.assertEquals(respassunto,"Teste Selenium com assert");

        message.submit();
        String respmsg = message.getAttribute("value");
        Assert.assertEquals(respmsg,
                "Gostaria de saber mais sobre a DOQ Consulting e como podemos ajudá-lo? Envie sua mensagem pelo site ou em nossas redes sociais.");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[class='btn btn-send']")));
        WebElement sendclick = driver.findElement(By.cssSelector("button[class='btn btn-send']"));
        sendclick.click(); /*Código comentado devido ao erro do webdriver com o firefox*/

//        wait.until(ExpectedConditions.presenceOfElementLocated(By.className("col-sm-7 col-sm-offset-1")));
//        WebElement validatemsg = driver.findElement(By.className("col-sm-7 col-sm-offset-1"));
//        String test = validatemsg.getText();
//        Assert.assertEquals(test," *Sua mensagem foi enviada com sucesso, logo mais um de nosso consultores irão avaliar o seu caso e entrar em contato. ");


    }
 
Example 18
Project: NoraUi   File: Step.java   View Source Code Vote up 3 votes
/**
 * Update a html input text with "".
 *
 * @param pageElement
 *            Is target element
 * @param keysToSend
 *            character to send to the element after {@link org.openqa.selenium.WebElement#sendKeys(CharSequence...) sendKeys} with textOrKey
 * @param args
 *            list of arguments to format the found selector with
 * @throws TechnicalException
 *             is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
 *             Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_ERROR_CLEAR_ON_INPUT} message (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void clearText(PageElement pageElement, CharSequence keysToSend, Object... args) throws TechnicalException, FailureException {
    try {
        WebElement element = Context.waitUntil(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(pageElement, args)));
        element.clear();
        if (keysToSend != null) {
            element.sendKeys(keysToSend);
        }
    } catch (Exception e) {
        new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_ERROR_CLEAR_ON_INPUT), pageElement, pageElement.getPage().getApplication()), true,
                pageElement.getPage().getCallBack());
    }
}
 
Example 19
Project: mot-automated-testsuite   File: WebDriverWrapper.java   View Source Code Vote up 2 votes
/**
 * Enters the specified text into the field.
 * <p>Note: This is a low-level way to locate the field. Please only use this method if the text <code>input</code>
 * doesn't have a corresponding label, otherwise use the <code>enterIntoField(String,String)</code> method using
 * the label text to identify the field.</p>
 * @param text  The text to enter
 * @param id    The field id
 */
public void enterIntoFieldWithId(String text, String id) {
    WebElement textElement = webDriver.findElement(By.id(id));
    textElement.clear();
    textElement.sendKeys(text);
}
 
Example 20
Project: oscm   File: WebTester.java   View Source Code Vote up 2 votes
/**
 * Takes the given value as input for the element with the given id.
 * 
 * @param id
 *            the element id
 * @param value
 *            the input value
 * @throws NoSuchElementException
 *             if element is not present
 */
public void writeValue(String id, String value) {
    WebElement element = driver.findElement(By.id(id));
    element.sendKeys(value);
}