0
votes

I am using firefox browser. I tried the mouse hover on the menu but not displaying its respective submenu when hover on the main menu using selenium webdriver.It only select the menu "Claims" and stops there only.Its not executing testScript further because on mouse hover submenu not displayed.So

HTML CODE

    <body>
<div id="div_LockPane" class="LockOff"/>
<div id="claim-newclaimsearch" class="page-wrap" data-menu-hovered="">
<div class="header">
<div class="row">
<div class="column small-12 large-2 logo">
<nav class="column small-12 large-10 navigation-container" role="navigation">
<ul class="main-menu">
<li>
<li class="active">
<a href="/Menu/Claims">
<div class="menu-icon">
<img src="/content/common/images/menu-icons/claims.png"/>
</div>
<span class="name">Claims</span>
</a><div class="arrow-container">
<div class="sub-menu-container">
<div class="row sub-menu">
<div class="column title-side">
<h2 class="title">Claims</h2>
</div>
<div class="column points-side">
<ul>
<li class="active">
<a href="/Claim/NewClaimSearch">New Claims</a>
</li>
<div class="search-page">
<div id="search-advanced-tools" data-state="collapsed">
<div class="row">
<div class="column">
<h2 class="action-title">New Claims</h2>
</div>
</div>

I have to hover on menu "Claims" and select submenu "NEW CLAIMS"

enter image description here

Selenium Code

//private final By PRODUCT_CATEGORY = By.linkText("Claims");
private final By PRODUCT_CATEGORY= By.xpath("//a[contains(.,'Claims')]");
private final By PRODUCT_SUBCATEGORY = By.linkText("NEW CLAIMS");

@Test()
void testLogincase2() throws Exception{

    Thread.sleep(2000);

    WebElement hoverBtn = driver.findElement(PRODUCT_CATEGORY);
            System.out.println("click on Claims");
            Thread.sleep(2000);
            Actions action = new Actions(driver);
            Thread.sleep(2000);
            action.moveToElement(hoverBtn).perform();
            Thread.sleep(1000);

            WebElement subElement = driver.findElement(PRODUCT_SUBCATEGORY);
            Thread.sleep(1000);
            action.moveToElement(subElement);
            System.out.println("No claims");
            Thread.sleep(2000);
            action.click();
            Thread.sleep(2000);
            action.perform();

    }

As you see in below attached image here the menu "Claims" got detected by driver as it colour become a bit darker then other menu .But the submenu is not displayed like as i have shown in above image. The mouse hover event is not working

enter image description here

2
is ur element move to "claim" options? - noor
yes it moves to menu "claims" - DoubtClear
if ur link is public, than it will be hepful for us to solve easily. - noor
How to know link is public or not because i dont have backend code - DoubtClear

2 Answers

0
votes

Once you get menu on mouse hover, no need to use action again. Just click on the sub-menu. Try below code after mouse hover

        WebElement subElement = driver.findElement(PRODUCT_SUBCATEGORY);
        subElement.click();
0
votes

Release ur first action before use it in second action.

action.moveToElement(hoverBtn).perform();

here u don't use release() method but u use this action in next.This is may be one of your problem.So for second click, try to create new action instance.

Second, for the next click, no need to use action, i think u can do this by using normal click function i mean by:

driver.findElement(PRODUCT_SUBCATEGORY).click();

And also debug ur code properly so that ur element locator is ok or not.