0

I have an link in HTML and I use Page Object pattern to write scripts with Selenium Webdriver. But my link is hidden and I can't perform MouseMove action when object is initialized with pageFactory.

Here is my class:

public class DashboardPage {
WebDriver driver;

@FindBy(xpath = Constants.admin)
public WebElement adminButton;
@FindBy(xpath = Constants.usersAndRoles)
public WebElement usersAndRolesButton;
@FindBy(xpath = Constants.users)
public WebElement usersButton;

public DashboardPage (WebDriver dr){
    driver =dr;
}

public UsersPage goToUsersPage(){
    adminButton.click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Actions builder = new Actions(driver);    
    builder.moveToElement(usersAndRolesButton).build().perform();
    //usersAndRolesButton.click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    usersButton.click();
    return PageFactory.initElements(driver, UsersPage.class);
}
Ahmed Yaslem
  • 123
  • 1
  • 4
  • 20

2 Answers2

0

Try using scroll to element and perform operation on it. Try following function.Pass your element to function,page will scrolled to that element and then perform any other operation-

public void scrollToElement(WebElement element){
 int elementPosition = element.getLocation().getY();
   elementPosition = elementPosition-200; // You can change 200 to any value if your page have sticky header       
   System.out.println(elementPosition);
   String js = String.format("window.scroll(0, %s)", elementPosition);
   ((JavascriptExecutor)driver).executeScript(js);

}

//other operation
element.click(); //etc....
Deepak
  • 336
  • 1
  • 3
  • 10
0

The following code worked for me.

@FindBy(xpath = Constants.usersLink)
public WebElement usersLink;

    public UsersPage goToUsersPage() {
            JavascriptExecutor usersPage = (JavascriptExecutor) driver;
            usersPage.executeScript("arguments[0].click();", usersLink);
            return PageFactory.initElements(driver, UsersPage.class);
        }
Ahmed Yaslem
  • 123
  • 1
  • 4
  • 20