I am stuck on it for a while now, so I thought I shall ask for help. I am trying to locate an element by name using page factory mechanism which uses in built findElement API. Element is there on web page, but still it cannot find it. Can anyone please point where I am doing wrong? Thanks.
@FindBy(how = How.NAME, using = "userName")
private WebElement userName;
public WebElement getUserName() {
return userName;
}
homepage.getUserName().sendKeys("test");
Your code seems fine. However you might need to add a wait before sendKeys since it might be possible that the page isn't loaded by that time.
WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5));
wait.Until(By.Id("login"));
Hope it helps!