Skip to content Skip to sidebar Skip to footer

How To Open A Webelement From A Hoover Menu Selenium Java

Hello I'm new using selenium and I was trying to execute some tests from a web page. This is my code: System.setProperty('webdriver.gecko.driver','C:\\DRIVERS\\geckodriver.exe');

Solution 1:

try using:

Actionsaction=newActions(driver);
WebElementmenu= driver.findElement(By.xpath("xpath for menu"));
WebElementitem= driver.findElement(by.cssSelector("css selector values for Búsqueda"));
action.moveToElement(menu).moveToElement(item ).click().build().perform();

Solution 2:

Try this below code using action class

WebElementmenu_element= driver.findElement(By.xpath("your_menu_xpath"));

WebDriverWaitwait=newWebDriverWait(driver, 10);   //Explicit wait method, wait for web-element till 10 seconds so, your driver should able to find the web-element.
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("Your_submemu_xpath"))));

WebElementsub_menu_element= driver.findElement(By.xpath("Your_submemu_xpath"));
Actionsaction=newActions(driver);
action.moveToElement(menu_element).moveToElement(sub_menu_element).click().build().perform();

Explanation:

1) First locate the menu element

2) Provide explicit wait method for few seconds so your driver may able to find the sub_menu_element that you want to go with.

3) After explicit wait locate the sub_menu element, that you want to go with.

4) Using Action class try to move element from menu to sub menu.

Post a Comment for "How To Open A Webelement From A Hoover Menu Selenium Java"