Selenium无法找到javascript元素

时间:2015-09-02 23:51:04

标签: javascript jquery selenium selenium-webdriver

我想使用以下代码登录页面:

driver.findElement(By.xpath(".//*[@id='uiPostGetPage']")).sendKeys("admin");

但是selenium找不到这个元素,因为我检查了源代码,没有一个名为uiPostGetPage的元素

有网站的源代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Airties</title>
<script type="text/javascript" src="/lang.js"></script>
<script type="text/javascript" src="/js/Definitions.js"></script>
<script type="text/javascript">
<!--
document.title = "AirTies " + __DEF_BuildProfile;
if (top.frames.length!=0)

top.location=self.document.location;
// -->

</script>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Cache-control" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<script language="JavaScript" type="text/JavaScript">
<!--
document.title = "AirTies " + __DEF_BuildProfile;
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->

</script>
</head>

<frameset rows="115,*" frameborder="NO" border="0" framespacing="0">
  <frame src="top_login.htm" name="topFrame" scrolling="NO" noresize >
  <frame src="loginmain.html" name="mainFrame">
</frameset>
<noframes>

<body>
</body></noframes>
<head>
<META HTTP-EQUIV="Cache-control" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="-1">
</head>
</html>

如果您查看,则没有任何元素包含登录代码。

我该怎么做才能发送这个隐藏的uiPostGetPage元素?

1 个答案:

答案 0 :(得分:1)

我怀疑所需的元素位于iframe 中。切换到它:

driver.switchTo().frame("mainFrame");