2016-08-26 36 views
1

我使用以下命令來導航Selenium中的菜單。它在Chrome中完美運行,但是在IE中,它最終會點擊我的目標下方的菜單,並且子菜單項變得完全無法訪問。Selenium無法通過moveToElement在IE中單擊正確的目標,在Chrome中工作

// Actions not supported by FireFox's Marionette Driver, use chrome or ie. 
Actions actions = new Actions(driver); 
WebElement menuHoverLink = driver.findElement(By.id("m7f8f3e49_ns_menu_INVENTOR_MODULE_a_tnode")); 
System.out.println("Found the inventory text"); 
actions.moveToElement(menuHoverLink); 

WebElement subLink = driver.findElement(By.id("m7f8f3e49_ns_menu_INVENTOR_MODULE_sub_changeapp_INVENTOR_a")); 
actions.moveToElement(subLink); 
actions.click(); 
actions.perform(); 

而且這裏是驅動初始化

System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer64.exe"); 
driver = new InternetExplorerDriver(); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

我希望能夠點擊適當的菜單項,繼續我的測試。

+0

您確定您要查找的屬性ID與IE相同嗎? –

回答

0

我設法通過將光標移到偏移量上來獲得工作解決方案。不知道這將在多個屏幕上運行得如何。

Actions actions = new Actions(driver); 
    WebElement menuHoverLink = driver.findElement(By.linkText(arg1)); 

    //<span id="m7f8f3e49_ns_menu_INVENTOR_MODULE_a_tnode">Inventory</span> 
    System.out.println("Found the inventory text"); 
    actions.moveToElement(menuHoverLink); 
    actions.moveByOffset(100, 10); 

    Thread.sleep(1000); 
    //actions.moveByOffset(45, 0); 
    WebElement subLink = driver.findElement(By. 
      id("m7f8f3e49_ns_menu_INVENTOR_MODULE_sub_changeapp_SRVITEM_a_tnode")); 
    actions.moveToElement(subLink, 100, 12) 
    .click().perform(); 
相關問題