简体   繁体   中英

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("ABCDEFG@g.com");
WebElement usernameElement = driver.findElement(By.id("username"));
String userName = usernameElement.getAttribute("value");
assertEquals("ABCDEFG@g.com", userName);

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

Thanks in advance,

^Best regards

What about this ?

WebElement emailElement = driver.findElement(By.id("email"));
emailElement.sendKeys("ABCDEFG@g.com");

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

String userName = usernameElement.getText(); // get the value
assertEquals("ABCDEFG@g.com", 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM