2014-12-04 27 views
-1

我必須單擊一個儀表板,單擊menuitem後獲得顯示。並且menuitem和儀表板都在不同的框架。點擊動態div元素,這是在內部框架使用java Selenium WebDriver

<html> 
    <head> 
    <frameset scrolling="no" framespacing="0" marginwidth="0" marginheight="0"  border="0" frameborder="0" rows="98,*"> 
     <frame scrolling="no" noresize="" marginwidth="0" marginheight="0" src="menu.jsp" name="menu"> 
      <script language="JavaScript"> 
      <script type="text/javascript" src="menu7_com.js" language="JavaScript"> 
       <div style="position: absolute; display: block; background-color: black; width: 1080px; height: 18px; z-index: 1101; top: 72px; left: 10px;"> 
       <div style="position: absolute; overflow: hidden; cursor: default; color: rgb(0, 0, 0); font-family: Arial;font-size: 9pt; font-weight: bold; font-style: normal; background-color: rgb(224, 224, 224); text-align:left; width: 110px; height: 16px; padding-left: 10px; padding-top: 2px; left: 0px; top: 0px;"> 
       <div style="position: absolute; overflow: hidden; cursor: default; color: rgb(0, 0, 0); font-family: Arial;   font-size: 9pt; font-weight: bold; font-style: normal; background-color: rgb(224, 224, 224); text-align:   left; width: 110px; height: 16px; padding-left: 10px; padding-top: 2px; left: 120px; top: 0px;"> 
    </div>  
     <frame scrolling="auto" style="scrollbar-base-color:blue;" noresize="" marginwidth="0" marginheight="0" src="Dashboard.do?action=DashBoard" name="display"> 
     <div style="position: absolute; overflow: hidden; cursor: default; color: rgb(0, 0, 0); font-family: Arial;   font-size: 9pt; font-weight: bold; font-style: normal; background-color: rgb(224, 224, 224); text-align:left; width: 110px; height: 16px; padding-left: 10px; padding-top: 2px; left: 120px; top: 0px;"> 
    </div> 
    </frameset> 
</html> 
+1

嗯,默認情況下,你不能點擊一個不可見的元素。你可以分享到該網站的鏈接以及目前爲止的代碼嗎?謝謝。 – alecxe 2014-12-04 07:49:42

+1

請從菜單項開始分享更多HTML代碼片段到您想要點擊的元素。 – Subh 2014-12-04 07:58:53

回答

0

正如您所提到的,只有在點擊其「父分區標記」後纔可見。 因此,您必須先將鼠標移至其父級Div元素,然後單擊其子元素。 您可以使用Action類移動到父元素,然後單擊其子元素。 我已經包含了正確的Child Div標籤的Xpath,就像您可以獲得其父級Div標籤的Xpath一樣。

以下是相同的示例。

 WebElement Parent_tag= driver.findElement(By.xpath("Xpath of Parent Div Tag")); 
     WebElement Child_tag= driver.findElement(By.xpath("//div(contains(text(),'Create Hierarchy'))")); 
     Actions action = new Actions(driver); 
     action.moveToElement(Parent_tag).click(Child_tag).perform(); 
0

對不起,我的問題是輕微的錯誤。實際上div的格式是不同的。但我找到了解決方案。

driver.switchTo().frame("menu"); 
WebElement MenuOne = driver.findElement(By.xpath("html/body/div[1]/div[1]")); 
MenuOne.click(); 
driver.switchTo().defaultContent(); 
driver.switchTo().frame("display"); 
WebElement Createborrower = driver.findElement(By.xpath("html/body/div[5]/div[3]")); 
Createborrower.click(); 
+0

以上答案完美適用於兩幀之間的處理。 – 2014-12-04 13:51:53

相關問題