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();
2 Answers 2
You can use the Actions API for that, given that the browser you use supports it. The following should do the trick with Chrome:
- Moves the mouse over the "Admin" button
- Waits until the "User Management" button is visible
- Moves the mouse over the "User Management" button
- Waits until the "Users" button is visible
- 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();
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– SQA_LEARN2017年06月14日 18:03:40 +00:00Commented Jun 14, 2017 at 18:03
Explore related questions
See similar questions with these tags.