6

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();
Alok
76011 silver badges25 bronze badges
asked Jan 24, 2017 at 9:40

2 Answers 2

5

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();
answered Jan 24, 2017 at 11:31
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();
alecxe
11.4k11 gold badges52 silver badges107 bronze badges
answered Jan 24, 2017 at 16:40
1
  • 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() ?? Commented Jun 14, 2017 at 18:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.