ABCDEFG
ABCDEFG

Reputation: 799

Selenium webdriver - Tab control

I am facing a challenge in my project. There are two text box's in a page and where First text box will accept an email ID and when user move his control to next text box email ID from First text box will populate automatically in the second text box. I need to validate this test case.

I tried with following code,

WebElement emailElement = driver.findElement(By.id("email"));
emailElement.sendKeys("[email protected]");
WebElement usernameElement = driver.findElement(By.id("username"));
String userName = usernameElement.getAttribute("value");
assertEquals("[email protected]", userName);

Can someone help me with webdriver java code to fetch value from second text box(username).

Thanks in advance,

^Best regards

Upvotes: 3

Views: 10369

Answers (1)

Sandro Munda
Sandro Munda

Reputation: 41030

What about this ?

WebElement emailElement = driver.findElement(By.id("email"));
emailElement.sendKeys("[email protected]");

WebElement usernameElement = driver.findElement(By.id("username"));
usernameElement.click(); // Here, autocomplete is done

String userName = usernameElement.getText(); // get the value
assertEquals("[email protected]", userName);

If you want to send the TAB key with selenium, you can do that :

emailElement.sendKeys(Keys.TAB);

All special keys are available here

Upvotes: 7

Related Questions