<li class= "Navbar-nav-item" > <a href= "#" id= "Cust" >xx management </a>
<ul class= "Navbar-dropdown-menu" ><li class= "dropitem-current" ><a href= "/customer/index" >xx list </A></LI&G t;<li class= "Navbar-dropitem" id= "list_2" ><a href= "/customer/communicateindex" >X X List </a></li></ul></li>
The first type:move the mouse to the element you want to hover over, get the displayed elements, and click on the code example below:
actions action = Actions ( Span style= "Font-family:consolas; Color: #6a3e3e; line-height:1.6; font-size:12pt; " >chrome action.movetoelement (chrome.findelement (by.id ("Cust")) . Perform (); //mouse moves to toelement element midpoint Thread. sleep (+); chrome.findelement (by. ID("list_2") ). Click (); //"XX list " Click event chrome.manage (). window (). Maximize (); //Window maximization action.release (); //mouse event release
PS:
- It is recommended to join the wait when hovering;
- Maximize the window due to poor mouse event stability recommendations;
- Recommended release after the mouse event has ended;
The second type:for the hidden drop-down option in the menu, it is displayed when the mouse hovers, calling action.movetoelement (Element). Build (). perform (); or Action.keydown (keys). Build (). Perform (); In general, it can be solved. At some point, however, you can use JavaScript to implement a click of a hidden element, with the following code examples: javascriptexecutor js = (javascriptexecutor) chrome; myjs="document.getelementsbyclassname (' dropitem-current ') [0].childnodes[0].click ();"; System. Out.print (MYJS); Js.executescript (MYJS);
Selenium methods for handling hidden elements