简体   繁体   中英

trouble clicking on dropdown sub-menu through selenium webdriver

I am automating a website using selenium webdriver. The problem i am facing is that when i click on a menu item, the submenu opens, (its actually a misplaced dropdown, ui problem) , i can find the element of the sub menu item i want to click on, but i am not able to click as i get an exception :

"Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Cannot click on element"

Is there any way i can click on this submenu item?

HTML code for the page:

<td class="menulevel1norm" id="PanelTable" onmouseover="this.className='menulevel1hl';" onmouseout="this.className='menulevel1norm'" onclick="PopupWin('Left',divMenu20111219065812407304,this,'.menuitempopuprownormal','.menuitempopuprowhighlight','','.menuitempopupscroll');">
Text -  Inbound  
<div id="divMenu20111219065812407304" style="border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; visibility: hidden; position: absolute;" name="actiondiv">
<div myonclick="window.parent.location.href='/smcfs/console/omreceipt.search';">
![enter image description here][4]Text - MENU_Receipt Console 

My Java Code for Webdriver :

 public static void main(String[] args) throws IOException, InterruptedException {
      Runtime rt = Runtime.getRuntime();
      rt.exec("taskkill /F /IM IEDriverServer.exe /T");
      WebDriver driver = UtilityMethods.driverinitialize();
      driver.get("xxxx");
      UtilityMethods.login(driver); 
      WebElement e1 = (new WebDriverWait(driver, 30)).until(ExpectedConditions.elementToBeClickable(By.id("wicket-generated-id-4")));
        e1.click();
        driver.switchTo().defaultContent();
        driver.switchTo().frame("frame4");
        String eletext;
         List<WebElement> elements = driver.findElements(By.id("PanelTable"));
         for(WebElement ele : elements){
             eletext = ele.getText();
             System.out.println(eletext);
             if(eletext.equals(" Inbound ")){
                 ele.click();
                 break;
             }
         }

         Thread.sleep(2000);
         List<WebElement> elements2 = driver.findElements(By.tagName("div"));
         for(WebElement ele1 : elements2){
             eletext = ele1.getAttribute("myonclick");
             System.out.println(eletext);
             if(eletext == null){ 
                 continue; }
    else if(eletext.equals("window.parent.location.href='/smcfs/console/omreceipt.search';")){
                     ele1.click();
                    break;
             }
         }



}

First, wait for all elements to appear on-page. Then if the element is properly visible and not overlapping with other parts of another element then click will perform. Another way is to locate a nearby proper element and then moving the pointer to some offset and then performing click.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM