0

During sign in on Yahoo mail, cursor is focused on Yahoo ID text field automatically. I want to verify whether cursor is focused or not on Yahoo ID text field. HTML for the text field is below:

<input name="login" id="username" maxlength="96" tabindex="1" value="">

How can I verify that Yahoo ID text field is focused or active? BTW, I am using WebDriver (Selenium 2) with java, TestNG as test framework

4

1 に答える 1

0

I think, the following code would work. Please try the following:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement actualYahooId = (WebElement)jse.executeScript("return document.getElementById('username');");
WebElement expectedYahooId = (WebElement)jse.executeScript("return document.activeElement;");
assertEquals(actualYahooId, expectedYahooId);
于 2012-08-24T11:55:30.217 に答える