I am new to selenium and trying to select an option (Job Title) from sub menu (Job) where main menu is 'Admin' on OrangeHRM website.
my script clicks on admin but instead of mouse hover on "Job"and selecting "Job Title", it mouse hovers on another main menu called "Leave". Please help where am I going wrong.
sAdminMenu.click();
System.out.println("Clicked on Admin menu ");
Thread.sleep(5000);
//job title selection
Actions action = new Actions (driver);
WebElement sAdminMenuJob = driver.findElement(By.xpath("//a[@id='menu_admin_Job']"));
action.moveToElement(sAdminMenuJob).build().perform();
Thread.sleep(5000);
WebElement sAdminMenuJobTitle = driver.findElement(By.xpath("//a[@id='menu_admin_viewJobTitleList']"));
action.moveToElement(sAdminMenuJobTitle).click().build().perform();
Thread.sleep(5000);
HTML
You can try JavascriptExecutor
:
WebElement sAdminMenuJobTitle = driver.findElement(By.xpath("//a[@id='menu_admin_viewJobTitleList']"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", sAdminMenuJobTitle);