简体   繁体   中英

Cannot click element inside frame for JSP webpage using Java selenium

I have a private JSP URL which has frames.

I'm sharing the snapshot of the same here.

在此处输入图片说明

As you can see in the snapshot I wish to click on "Replication management" then "Manage queues" which is in the left frame.

I'm sharing View Page Source & View Frame Source of the same here.

View Page Source:

<!-- Mark the file as a JSP and set up the classes to import -->

<HEAD>
<link rel="icon" href="/IDSWebApp/IDSgui/tds-16.ico" type="image/x-icon" />
<LINK REL="SHORTCUT ICON" HREF="/IDSWebApp/IDSgui/tds-16.ico" type="image/x-icon">
</HEAD>



<HTML dir='ltr'>

<HEAD>
<TITLE>
IBM Security Directory Server Web Administration Tool
</TITLE>
</HEAD>

<FRAMESET ROWS="40,*">


<FRAME SRC="/IDSWebApp/IDSjsp/IDSBannerFrame.jsp" TITLE="Banner Frame" NAME="BannerFrame" MARGINWIDTH="1" MARGINHEIGHT="1" SCROLLING="NO" NORESIZE FRAMEBORDER="1" FRAMESPACING="1" BORDERCOLOR="#000000">

<FRAMESET COLS="20%,80%">

<FRAME SRC="/IDSWebApp/IDSjsp/IDSNavFrame.jsp" TITLE="Navigation frame" NAME="NavFrame" MARGINWIDTH="1" MARGINHEIGHT="1" SCROLLING="AUTOMATIC" FRAMEBORDER="1" FRAMESPACING="1" BORDERCOLOR="#000000">

<FRAME SRC="/IDSWebApp/IDSjsp/IDSWorkFrame.jsp" TITLE="Work Area Frameset" NAME="WorkArea" MARGINWIDTH="1" MARGINHEIGHT="1" SCROLLING="AUTOMATIC" FRAMEBORDER="1" FRAMESPACING="1" BORDERCOLOR="#000000">

<NOFRAMES>
<BODY>
The IBM Security Directory Server Web Administration Tool does not currently support Web browsers that do not support frames. Contact the Directory Server administrator to find a Web browser that supports frames.
</BODY>
</NOFRAMES>

</FRAMESET>

<NOFRAMES>
<BODY>
The IBM Security Directory Server Web Administration Tool does not currently support Web browsers that do not support frames. Contact the Directory Server administrator to find a Web browser that supports frames.
</BODY>
</NOFRAMES>

</FRAMESET>

</HTML>

View Frame Source:

<!-- Mark the file as a JSP and set up the classes to import -->

<HTML dir='ltr'>

<HEAD>
<style type="text/css">
FONT { font-size: 100%; }
.navHeading {PADDING-TOP: 4px;PADDING-BOTTOM: 4px;PADDING-LEFT: 2px;FONT-WEIGHT: bold;FONT-SIZE: 70%;FONT-FAMILY: Arial,Helvetica,sans-serif;BACKGROUND-COLOR: #D1D9E8}
.navTask {PADDING-LEFT: 2px;FONT-SIZE: 60%;FONT-FAMILY: Arial,Helvetica,sans-serif;BACKGROUND-COLOR: #D1D9E8}
</style>
<TITLE>
Navigation frame
</TITLE>
</HEAD>
<Body bgColor="#D1D9E8">

<table border=0 cellpadding=0 cellspacing=0 width="100%" bgcolor="#D1D9E8" xbgcolor="#000000">

<tr><td nowrap class="navHeading">
<IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" HEIGHT="16" WIDTH="16">
<A HREF="/IDSWebApp/IDSWelcome" Target="WorkFrame" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnDocument.gif" title="Click here to launch Introduction" alt="Click here to launch Introduction" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><font size="2" color="#454589" face="Arial,Helvetica,sans-serif" >Introduction</Font></A>
</td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idspasswd#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open User properties" alt="Click here to open User properties" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open User properties" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">User properties</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idssrvadm#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Server administration" alt="Click here to open Server administration" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Server administration" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Server administration</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idsproxy#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Proxy administration" alt="Click here to open Proxy administration" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Proxy administration" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Proxy administration</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idsdmt#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Schema management" alt="Click here to open Schema management" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Schema management" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Schema management</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idsdirmgmt#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Directory management" alt="Click here to open Directory management" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Directory management" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Directory management</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idsreplication#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Replication management" alt="Click here to open Replication management" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Replication management" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Replication management</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idstid#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Realms and templates" alt="Click here to open Realms and templates" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Realms and templates" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Realms and templates</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<A HREF="/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idsusrgrp#spot" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnTnClosed.gif" title="Click here to open Users and groups" alt="Click here to open Users and groups" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/WnFolderClosed.gif" title="Click here to open Users and groups" alt="" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><Font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Users and groups</Font></A></td></tr>
<tr><td nowrap class="navHeading">
<IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" HEIGHT="16" WIDTH="16">
<A HREF="/IDSWebApp/IDSLogout" Target="_top" BORDERCOLOR="#000000"><IMG SRC="/IDSWebApp/IDSgui/WnDocument.gif" title="Click here to launch Logout" alt="Click here to launch Logout" align="texttop" border="0" HEIGHT="16" WIDTH="16"><IMG SRC="/IDSWebApp/IDSgui/Blank.gif" alt="" border="0" align="texttop" HEIGHT="16" WIDTH="2"><font size="2" color="#454589" face="Arial,Helvetica,sans-serif">Logout</Font></A>
</td></tr>

</table>
</BODY>
</HTML>

I tried to get the frame using the below selenium java code (3 attempts) but it does not work.

driver.switchTo().defaultContent();

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@title='Navigation frame']")));
driver.switchTo().frame(driver.findElement(By.xpath(".//iframe[@title='Navigation frame']")));
driver.switchTo().frame(driver.findElement(By.xpath(".//iframe[@src='http://myhost:1200/IDSWebApp/IDSjsp/IDSNavFrame.jsp?opennav=idsreplication#spot']")));

I get the following error:

*** Element info: {Using=xpath, value=//iframe[@title='Navigation frame']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at pack.QueueMonitor.testQualysScan(QueueMonitor.java:112)
at pack.QueueMonitor.main(QueueMonitor.java:185)

Can you please suggest?

When you are NOT sure how nested iframes are working you can try following ways to check if iframe there then switch it and check again for another iframe else check next iframe and so on.Worth to give it a try.

//Checking nested frames here
        if (driver.findElements(By.xpath("//iframe[@name='BannerFrame']")).size()>0)
        {
            System.out.println("inside frame 1");
            driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='BannerFrame']")));
            if (driver.findElements(By.xpath("//iframe[@name='NavFrame']")).size()>0)
            {
                System.out.println("inside frame 2");
                driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='NavFrame']")));

                if (driver.findElements(By.xpath("//iframe[@name='WorkArea']")).size()>0)
                {
                    System.out.println("inside frame 3");
                    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='WorkArea']")));

                }

            }
            else
            {
                if (driver.findElements(By.xpath("//iframe[@name='WorkArea']")).size()>0)
                {
                    System.out.println("inside frame 3");
                    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='WorkArea']")));

                }

            }


        }
        else
        {
            if (driver.findElements(By.xpath("//iframe[@name='NavFrame']")).size()>0)
            {
                System.out.println("inside frame 2");
                driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='NavFrame']")));

                if (driver.findElements(By.xpath("//iframe[@name='WorkArea']")).size()>0)
                {
                    System.out.println("inside frame 3");
                    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='WorkArea']")));

                }       

            }
            else
            {
                if (driver.findElements(By.xpath("//iframe[@name='WorkArea']")).size()>0)
                {
                    System.out.println("inside frame 3");
                    driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='WorkArea']")));

                }   

            }


        }

        //Click on Replication management link
        WebDriverWait wait=new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[./font[text()='Replication management']]"))).click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM