Selenium methods for handling hidden elements

Source: Internet
Author: User

<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:
    1. It is recommended to join the wait when hovering;
    2. Maximize the window due to poor mouse event stability recommendations;
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.