4

I am trying to select/navigate to a menu item in the provided URL. I tried Actions but It was not working.

https://enterprise-demo.orangehrmlive.com/auth/login

uid/pwd : admin/admin

I wanted to select a menu navigation (e.g: Admin->User Management->User Roles)

By admin = By.id("menu_admin_viewAdminModule");
By uMgmt = By.id("menu_admin_UserManagement");
By uRoles = By.id("menu_admin_viewUserRoles");
By username = By.id("searchSystemUser_userName");
By search = By.id("searchBtn");

WebDriver driver2 = driver;
Actions act = new Actions(driver2);

WebElement wadmin = driver2.findElement(admin);
WebElement wusermgmt = driver2.findElement(uMgmt);
WebElement wuserroles = driver2.findElement(uRoles);

act.moveToElement(wadmin).moveToElement(wusermgmt).moveToElement(wuserroles).click().build().perform();
3

You can use the Actions API for that, given that the browser you use supports it. The following should do the trick with Chrome:

  1. Moves the mouse over the "Admin" button
  2. Waits until the "User Management" button is visible
  3. Moves the mouse over the "User Management" button
  4. Waits until the "Users" button is visible
  5. Clicks the "Users" button:

Java

WebElement admin = driver.findElement(By.xpath("//b[contains(., 'Admin')]"));

new Actions(driver).moveToElement(admin).perform();

WebElement userManagement = new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.id("menu_admin_UserManagement")));
new Actions(driver).moveToElement(userManagement).perform();

WebElement users = new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.id("menu_admin_viewSystemUsers")));
users.click();
1

You can perform this by using linkText or partialLinkText:

// System.setProperty("webdriver.chrome.driver", "yourChromeLocation\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://enterprise-demo.orangehrmlive.com/");
driver.findElement(By.id("txtUsername")).sendKeys("Admin");
driver.findElement(By.id("txtPassword")).sendKeys("admin");
driver.findElement(By.id("btnLogin")).click();

WebElement admin = driver.findElement(By.xpath("//b[contains(., 'Admin')]"));

new Actions(driver).moveToElement(admin).perform();

WebElement userManagement = new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.id("menu_admin_UserManagement")));
new Actions(driver).moveToElement(userManagement).perform();
//driver.findElement(By.partialLinkText("User Roles")).click();

WebElement users = new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.linkText("User Roles")));
users.click();
  • Thanks @Sean Das, In the Above question I tried sequence of Action elements like act.moveToElement(wadmin).moveToElement(wusermgmt).moveToElement(wuserroles).perform() does this work? or after every action we need to do build().perform() ?? – SQA_LEARN Jun 14 '17 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.