2017-04-07 30 views
0

下面是movehover上下拉

<div id="pMenu_root_10" class="itemBorder" style="position: absolute; left: 809px; top: 0px; width: 58px; height: 98px; z-index: 1000; background: rgb(190, 213, 231) none repeat scroll 0% 0%; cursor: default;" onmouseover="pMenu.over('root',10)" onmouseout="pMenu.out('root',10)" onclick="pMenu.click('root',10)"> 
    <div class="lowText" style="font-size: 11px; FONT-FAMILY: Arial; color: #0066CC; position: absolute; left: 1px; top: 1px; width: 56px; height: 96px">Reports</div> 
</div> 

我試圖鼠標硒懸停,這樣我可以選擇當前的子菜單中的某個HTML代碼。但我的硒不能獲得元素

WebElement ele = driver.findElement(By.xpath(".//div[@id='pMenu_root_10']/div[text()='Reports']"));  
Actions act = new Actions(driver); 
act.moveToElement(ele).perform(); 

我嘗試使用abosulte的Xpath以及由Firepath給出

.//*@id='loginFormName']/table[2]/tbody/tr/td[2]/table[1]/tbody/tr[5]/td/div/table/tbody/tr/td[3]/img 

請幫我找到這個問題

下面是錯誤返回

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//div[@id='pMenu_root_10']/div[text()='Reports']"} 
+0

嘗試這樣的回答:http://stackoverflow.com/questions/43242950/how-to-open-a-webelement-from-a-hoover-menu-selenium-java/43247339#43247339 –

+0

仍然給同樣的錯誤。它仍然沒有得到pMenu_root_10 –

+0

請通過錯誤,你可以請分享您的網站網址? –

回答

0

輸入後用戶名密碼到站點,使用下面提到的代碼來訪問子菜單。

driver.findElement(By.id("login_button")).click(); 

WebDriverWait after_login = new WebDriverWait(driver, 10); 
after_login.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='parent_25']/a[contains(text(), 'Projects, Delivery & Sales')]")))); 

WebElement menu_element = driver.findElement(By.xpath("//div[@id='parent_25']/a[contains(text(), 'Projects, Delivery & Sales')]")); 
menu_element.click(); 

WebDriverWait wait = new WebDriverWait(driver, 10); 
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='parentGroup_25']/..//div[@class='hreftheme_AppLinks_sub_links_Li_Megamenu']/a[contains(text(), 'Integrated Project Management System')]")))); 

WebElement sub_menu_element = driver.findElement(By.xpath("//div[@id='parentGroup_25']/..//div[@class='hreftheme_AppLinks_sub_links_Li_Megamenu']/a[contains(text(), 'Integrated Project Management System')]")); 
sub_menu_element.click(); 

WebDriverWait IPMS_sub_menu_launch_button = new WebDriverWait(driver, 10); 
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='content']/..//following::td/img[@alt='Launch IPMS']")))); 

driver.findElement(By.xpath("//div[@id='content']/..//following::td/img[@alt='Launch IPMS']")).click(); 
Thread.sleep(8000); 

String childWindow = (String) driver.getWindowHandles().toArray()[1]; 
driver.switchTo().window(childWindow); // Switch to newly opened window. 
System.out.println("Switch to new tab."); 

driver.findElement(By.xpath("//form[@id='loginFormName']/..//following::td/img[@src='images/go_on.gif']")).click(); // After New tab, Webelement is easily accessible. 
Thread.sleep(8000); 

    try 
    { 
     String report_page_url = driver.getCurrentUrl(); 
     System.out.println(report_page_url); 

     String url = "https://ipmsapp.ultimatix.net/webipms/calhome_new.jsp"; 

     if(report_page_url.equals(url)) 
     { 
      System.out.println("I am on the report page."); 
     } 
    } 
    catch(Exception e) 
    { 
     System.out.println("Report page not open."); 
    }