Use Selenium to press tab and then write with java
I want selenium to press "TAB" for me and then write something in the
focused field, now I know that I can use
sendKeys(Keys.TAB)
But as I understand it That require a locator behind it, I want to test
the tab order of my page and to do so, I want to be able to focus on my
first element only, then tab my way through the page like this:
--THE ELEMENTS IN THE TAB ORDER THEY ARE SUPOSED TO BE--
String[] elementArray = {"firstname","lastname", "phone", "email"};
for(int x = 0; x < 4; x = x+1)
{
WebElement theElement = driver.findElement(By.id(elementArray[x]));
if (x == 0) {driver.theElement.sendKeys(x)}
else{driver.(TheCurrentlyFocusedElement).sendKeys(x)}
String elementval = theElement.getAttribute("value");
assertEquals(x, elementval);
(TheCurrentlyFocusedElement).sendKeys(Keys.TAB);
}
So the question is, is there a method I can use that allows me to use the
currently focused element as a locator? ie:
driver.focusedElement().sendKeys(Keys.TAB); ?
No comments:
Post a Comment