2015-09-02 92 views
1

我想做一個登錄頁面與此代碼:硒找不到的JavaScript元素

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

而是因爲我檢查源代碼硒無法找到這個元素沒有哪個叫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

我懷疑想要的元素位於iframe之內。切換到:

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

非常感謝你解決了我的問題。 – CyberTR