javaseleniumselenium-chromedriverframeset

Expand a menu inside frame with selenium java


I am trying to expand the option "Applications":

enter image description here

And this is its html:

enter image description here

What I have done until now:

// Wait until presence of navigation frame
element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/frameset/frameset/frame[1]")));
// switch to navigation frame
driver.switchTo().frame(driver.findElement(By.name("navigation")));
// Wait until presence of Aplications option
element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div/table/tbody/tr[2]/td/div[5]/a")));
// Click to expand Aplicactions options
element.click();

When it step into click I can see it is positioned over the option of Aplications because it is showing the tooltip / title "Aplications" like if we put the mouse over the option and the href of this option downside left javascript:expandCollapse('2');

I know the code is running until here because the other piece of code for login is working.

What I am not sure is the switch to frame because I have looked up for frameset and it shows that we can switch directly to the frame.

I am new, I apologize if this is messy. If something is missing to find the error, tell me to edit the post.

Thanks in advance.

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link href="" rel="styleSheet" type="text/css">
    <title></title>
</head>
<frameset name="ISCmain" rows="35,*" frameborder="1" border="1" resize="yes">
    <frame title="Header mark message" src="" name="header"
        noresize="" scrolling="no" marginwidth="0" marginheight="0">
        <frameset cols="25%,*" resize="yes">
            <frame title="Navigation mark" src="" name="navigation"
                style="border-right: 1px solid #d7d7d7;" resize="yes" marginwidth="10" marginheight="10">
                <html>
                <head>
                </head>
                <body style="direction:ltr" marginwidth="10" marginheight="10" onload="initAll();" class="navtree"
                    leftmargin="0" topmargin="0">
                    <div style="direction:ltr">
                        <link href="" rel="styleSheet" type="text/css">
                        <script language="javascript">
                        </script>
                        <div class="navBody" style="background-color:#FFFFFF;">
                            <table height="26" width="100%" cellspacing="0" cellpadding="0"
                                style="background-color:#FFFFFF;">
                                <tbody>
                                    <tr height="26" style="border-left: 1px solid #3970B1;background-color:#FFFFFF">
                                        <td class="wpsGpFilter" valign="center" align="left" width="100%"
                                            style="background-image:url(/ibm/console/images/isclite/grpfilter_background.gif);background-repeat: repeat-x;">
                                            <select name="navFilterSelection" id="navFilterSelection" dir="ltr"
                                                onchange="determineAction();">
                                                <option value="allTasks" selected="" label=""></option>
                                                <option value="com.ibm.isclite.MyTaskFilter" label=""></option>
                                                <option value="PF+com.ibm.websphere.product" label="">
                                                </option>
                                            </select>
                                            <noscript>
                                                <input type="submit" title='' value=''>
                                            </noscript>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="left" colspan="2" class="navtree" style="background-color:#FFFFFF">
                                            <ul class="nav-child" dir="ltr">
                                                <li class="navigation-bullet"><a style="text-decoration:none"
                                                        href="/ibm/console/navigation.do?wpageid=com.ibm.isclite.welcomeportlet.layoutElement.A&amp;moduleRef=com.ibm.isclite.ISCAdminPortlet"
                                                        target="detail" dir="ltr" title=""></a></li>
                                            </ul>
                                            <div nowrap="" class="main-task" style="margin-left:0.3em;"><a
                                                    style="color:#000000;text-decoration:none;"
                                                    href="javascript:expandCollapse('0');" title=""><img
                                                        src="/ibm/console/images/arrow_collapsed.gif" title="Expand"
                                                        alt="Expand" id="I0" border="0" align="absmiddle"></a></div>
                                            <div class="nav-child-container" style="margin-left: 0.3em; display: none;"
                                                id="N0">
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/navigatorCmd.do?forwardName=guidedactivity.resource&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a></li>
                                                </ul>
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/navigatorCmd.do?forwardName=guidedactivity.web&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a></li>
                                                </ul>
                                            </div>
                                            <div nowrap="" class="main-task" style="margin-left:0.3em;"><a
                                                    style="color:#000000;text-decoration:none;"
                                                    href="javascript:expandCollapse('1');" title=""><img
                                                        src="/ibm/console/images/arrow_collapsed.gif" title="Expand"
                                                        alt="Expand" id="I1" border="0" align="absmiddle"></a></div>
                                            <div class="nav-child-container" style="margin-left: 0.3em; display: none;"
                                                id="N1">
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/navigatorCmd.do?forwardName=ApplicationServer.content.main&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a></li>
                                                </ul>
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/navigatorCmd.do?forwardName=WebServer.content.main&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a></li>
                                                </ul>
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/com.ibm.ws.console.sib.sibresources.forwardCmd.do?forwardName=SIBMQServer.content.main&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a>
                                                    </li>
                                                </ul>
                                            </div>
                                            <div nowrap="" class="main-task" style="margin-left:0.3em;"><a
                                                    style="color:#000000;text-decoration:none;"
                                                    href="javascript:expandCollapse('2');" title="Aplications"><img
                                                        src="/ibm/console/images/arrow_expanded.gif" title="Expand"
                                                        alt="Expand" id="I2" border="0"
                                                        align="absmiddle">Aplications</a></div>
                                            <div class="nav-child-container" style="margin-left: 0.3em; display: block;"
                                                id="N2">
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/navigatorCmd.do?forwardName=ApplicationDeployment.content.main&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a>
                                                    </li>
                                                </ul>
                                                <ul class="nav-child" dir="ltr">
                                                    <li class="navigation-bullet"><a style="text-decoration:none"
                                                            href="/ibm/console/com.ibm.ws.console.appmanagement.action.forwardCmd.do?forwardName=appmanagement.upload&amp;WSC=true"
                                                            target="detail" dir="ltr" title=""></a></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </body>
                </html>
                <frame title="Content Mark"
                    src="/ibm/console/navigation.do?wpageid=com.ibm.isclite.welcomeportlet.layoutElement.A&amp;moduleRef=com.ibm.isclite.ISCAdminPortlet"
                    name="detail" resize="yes" marginwidth="0" marginheight="0">
        </frameset>
</frameset>
<noframes>
    ...
</noframes>
</html>

Solution

  • Whenever you encounter frameset remember you don't need to switch over it to let selenium interact with inside element.

    Instead do switch to frame itself (Implementing WebDriverWait for more stability):

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("navigation")));
    

    and finally your desired element you can pick :

    element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div/table/tbody/tr[2]/td/div[5]/a")));
    // Click to expand Aplicactions options
    element.click();
    

    It not a recommendation to use Absolute xpath switch to relative xpath.