Selenium 无法使用鼠标悬停访问子菜单链接

Selenium 无法使用鼠标悬停访问子菜单链接,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我正在尝试访问子菜单链接什么是Flex?在关于Flex的下面 使用SeleniumWeb驱动程序 无论何时执行鼠标悬停,在我访问子菜单之前,子菜单都会高亮显示并消失 *导入了一些不必要的包。请不要介意。 代码: 请帮忙 谢谢和问候, 公羊 注意:Thread.sleep不是一个好的实践。只需在您的程序或/和WebDriverWait中使用隐式等待即可。请格式化代码。最好等到DOM准备就绪,否则这些问题总会出现。如果答案有用,请投赞成票- package com.ram.workingtitle;

我正在尝试访问子菜单链接什么是Flex?在关于Flex的下面

使用SeleniumWeb驱动程序

无论何时执行鼠标悬停,在我访问子菜单之前,子菜单都会高亮显示并消失

*导入了一些不必要的包。请不要介意。 代码:

请帮忙

谢谢和问候, 公羊


注意:Thread.sleep不是一个好的实践。只需在您的程序或/和WebDriverWait中使用隐式等待即可。

请格式化代码。最好等到DOM准备就绪,否则这些问题总会出现。如果答案有用,请投赞成票-
package com.ram.workingtitle;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;  
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Alert;
import org.openqa.selenium.interactions.Actions;
import static org.testng.Assert.assertTrue;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;

public class Mouseover {
    public static void main(String[] args) throws Exception
    {
        WebDriver driver= new FirefoxDriver();
        driver.navigate().to("http://flex.apache.org/");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);        

        /*
        Used Firepath for generating xpath
        */
        WebElement element=driver.findElement(By.xpath(".//*[@id='nav']/li[2]/a"));
        WebElement sub=driver.findElement(By.xpath(".//*[@id='nav']/li[2]/ul/li[1]/a"));

        Actions action=new Actions(driver);
        action.moveToElement(element).build().perform();

        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

        action.moveToElement(sub).build().perform();

        System.out.println("executed");
    }
}
   Actions action = new Actions(webDriver); 
            action.moveToElement(webDriver.findElement(By.xpath("//*[@id='nav']/li[2]/a")))
            .build()
            .perform();
            Thread.sleep(5000);
            webDriver.findElement(By.xpath("//*[@id='nav']/li[2]/ul/li[1]/a")).click();