I was testing this website using selenium in java https://opensource-demo.orangehrmlive.com/ Im stuck in this part of the testing , where i have to check whether the dropdown contains title "Job Titles"
Actions action1 = new Actions(driver);
action1.moveToElement(driver.findElement(By.xpath("//*[@id=\"app\"]/div[1]/div[1]/header/div[2]/nav/ul/li[2]"))).build().perform();
Using the above code it is hovering over The "Job" but not clicking it. I tried using linktext, partial text, select but every time its showing "element not found" and even tried using wait.
One issue is that you need to *click* the "Job" menu item, not hover it. You don't need Actions
in this case. I updated your XPath to be less brittle.
The code below works.
driver = new ChromeDriver();
driver.manage().window().maximize();
String url = "https://opensource-demo.orangehrmlive.com";
driver.get(url);
// Log in
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[name='username'"))).sendKeys("Admin");
driver.findElement(By.cssSelector("[name='password'")).sendKeys("admin123");
driver.findElement(By.cssSelector("button")).click();
// Navigate menus
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Admin']"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Job ']"))).click();
// Test for existence of "Job Titles" dropdown option
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[@class='oxd-dropdown-menu']/li/a[text()='Job Titles']")));
} catch (TimeoutException e) {
Assert.fail("The 'Job Titles' dropdown option is not present.");
}