Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 978
ABCDEFG Avatar asked Jul 12 '26 09:07

ABCDEFG


1 Answers

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

like image 156
Sandro Munda Avatar answered Jul 14 '26 22:07

Sandro Munda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!