1

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" enter image description here

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.

JeffC
  • 22,180
  • 5
  • 32
  • 55

2 Answers2

1

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.");
}
JeffC
  • 22,180
  • 5
  • 32
  • 55
0

One question can you see select tag in above mentioned web page??

If select tag is present for that drop-down on that page then you can easily get values of drop-down using below code

Webelement el=driver.findelement(By.xpath("")); 1.Select sc=new Select(ele);

sc.selectByindex(0);or selectByvisibletext()or selectByvalue()