Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sendKeys() in Selenium web driver

I am new to Selenium. I just want to send keys to a username text box and send a tab key both at a time so that text box can check for availability of username.

Here is the code:

 driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName");
 driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys(Keys.TAB);

But this one is not working.

like image 793
Niks Avatar asked Oct 09 '13 09:10

Niks


People also ask

What are the various ways of sendKeys in Selenium?

driver. findElement(By. xpath(".//div/input[starts-with(@id,'4') and @class=' input' and @type='text' and @placeholder='']")). sendKeys("text");

What is implementation of sendKeys method?

This implementation of the sendKeys() method sends a sequence of characters/keys to a specific web element, which passes as the first parameter to the method.

Can we enter text without using sendKeys ()?

Yes, use javascript executer.


1 Answers

I doubt for Keys.TAB in sendKeys method... if you want to use TAB you need to do something like below:

Actions builder = new Actions(driver);
builder.keyDown(Keys.TAB).perform()
like image 179
Paras Avatar answered Sep 28 '22 10:09

Paras