Mangala Hegde
Mangala Hegde

Reputation: 27

Unable to click link in li tag in selenium

I need to click a link which is inside

  • and tag

    I tried this but not able to click.

    driver.findElement(By.xpath("//div[(@class,'menuRoot')]")).click();
    

    Note : this is inside the frame

    below is the html code

    <div class="menuRoot">
      <ul>
        <li onclick="selectRootItem(this)" documentid="1678" shrinkmenu="1"><a class="menu1" href="
                    http://www.intellipen.LegalAndGeneral.pc/Resources/System/pages/read.aspx?DocID=1678" onclick="showLoading()" target="fraMain"><img src="
                      /Resources/System/images/icons/binoculars.png">Search</a></li>
        <li onclick="selectRootItem(this)" documentid="1585"><a class="menu1" href="
                    http://www.intellipen.LegalAndGeneral.pc/Resources/System/pages/read.aspx?DocID=1585" onclick="showLoading()" target="fraMain"><img src="
                      /Resources/System/images/icons/member-data.png">Member</a></li>
        <li onclick="selectRootItem(this)" documentid="1581"><a class="menu1" href="
                    http://www.intellipen.LegalAndGeneral.pc/Resources/System/pages/read.aspx?DocID=1581" onclick="showLoading()" target="fraMain"><img src="
                      /Resources/System/images/icons/member-wizard.png">Wizards</a></li>
        <li onclick="selectRootItem(this)" documentid="1605"><a class="menu1" href="
                    http://www.intellipen.LegalAndGeneral.pc/Resources/System/pages/read.aspx?DocID=1605" onclick="showLoading()" target="fraMain"><img src="
                      /Resources/System/images/icons/browser.png">Establishment</a></li>
        <li onclick="selectRootItem(this)" documentid="1653"><a class="menu1" href="
                    http://www.intellipen.LegalAndGeneral.pc/Resources/System/pages/read.aspx?DocID=1653" onclick="showLoading()" target="fraMain"><img src="
                      /Resources/System/images/icons/startup.png">Workflow</a></li>
    

    Upvotes: 1

    Views: 1605

  • Answers (1)

    Sureshmani Kalirajan
    Sureshmani Kalirajan

    Reputation: 1938

    You can click on the menu based on the text present in the menu. Here is some samples,

    Search Menu item--

    driver.findElement(By.xpath("//a[contains(text(),'Search')]//parent::li")).click();
    

    Member menu item --

    driver.findElement(By.xpath("//a[contains(text(),'Member')]//parent::li")).click();
    

    Upvotes: 1

    Related Questions