Reputation: 291
My scenario: 1. Click on the Forgot username and password 2. Input wrong user ID and press tab. 3. Modal dialog appears with wrong ID text. 4. Accept the alert
Expected behavior: Focus should be on the user ID text box.
Actual behavior: In IE11- Through automation and manual the focus is on the userID text box. In Chrome - Manual execution the focus is on the user ID textbox. But through automation the focus is on 'Ok' button(some other button in the page).
Why there is such a difference in behavior? Selenium WebDriver-2.53.0 Chrome-49.0
Upvotes: 0
Views: 125
Reputation: 17553
You can use JavascriptExecutor
as below:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('elementid').focus();");
Hope it will help you :)
Upvotes: 1