Selenium webdriver - tab control
My project has a task. There are two text boxes on the page and the first text box will accept the email id and when the user moves their control to the next text box. The email ID from the first text box will automatically fill in the second text box. I need to check this test case.
I have tried with the 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 textbox (username).
Thanks in advance,
^ Best wishes
+3
source to share
1 answer
How 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 key TAB
using selenium, you can do this:
emailElement.sendKeys(Keys.TAB);
+7
source to share