0

I am new to selinum , during mouse hover(Request button) two button will be display on the screen.

1.User Status button
2. confirm user button

On click of User status button particular javascript function should be trigger..

I tried the below code, but it doesn't work.

WebElement subMenu = 
driver.findElement(By.xpath("//*[@id='menu']/ul/li[2]/a"));
actions.moveToElement(subMenu);
actions.click().build().perform();

HTML Structure :-

<div id="menu">         
        <ul id="MenuBar"> 
                <li id="MainLink">
                    <a href="javascript:add();">add</a>
                </li> 
                <li id="MainLink"><a>Requests</a>
                    <ul>
                        <li><a href="javascript:check();">User Status</a></li>
                        <li><a href="javascript:confirm();">Confirm User</a></li>
                    </ul>
                </li> 
                <li id="PrimaryLink">
                   <a href="javascript:update();">Update</a>
                    <ul></ul>
                </li>                    
        </ul>
    </div>
Giri
  • 127
  • 2
  • 5
  • 15

2 Answers2

1

Here is the step-wise solution to your Question:

  1. Locate the Request button & store the element:

    WebElement ele = driver.findElement(By.xpath("xpath_request_button"));
    
  2. Use Actions class to hover over the Request button:

    Actions act = new Actions(driver);
    act.moveToElement(ele).build().perform();
    
  3. Create a list using findElements to match the common xpath of all the elements within as:

        List<WebElement> links = driver.findElements(By.xpath("common_xpath"));
    
  4. Next you can even print the size of the list to know the number of elements within the list as follows:

    int total_count = links.size();
    System.out.println(total_count);
    

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

in case you are not receiving any errors with your code and your click is success but is not able to trigger the javascriptthen you may want to make use of JavascriptExecutor function as below:

   JavascriptExecutor js = ((JavascriptExecutor ) driver);
   js.executeScript("javascript:check();");

above code will execute the javascript function for you.

Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46