我有一个带有框架的私有JSP URL。
我在这里共享相同的快照。
您可以在快照中看到,我希望单击“复制管理”,然后单击左侧框架中的“管理队列”。
我在这里共享相同的“查看页面源”和“查看框架源”。
查看页面来源:
<!-- 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>
查看框架源:
<!-- 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>
我尝试使用以下硒java代码获取框架(3次尝试),但是它不起作用。
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']")));
我收到以下错误:
*** 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)
你能建议吗?
答案 0 :(得分:0)
如果不确定嵌套iframe的工作方式,可以尝试按照以下方法检查iframe是否在那里,然后将其切换并再次检查另一个iframe,然后再检查下一个iframe,以此类推。值得一试。
//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();