对于所有无法打开鼠标悬停菜单的Web驱动程序,硒都存在问题。对元素Web驱动程序的Xpath的充分提示无法打开鼠标悬停(CatMenu),并且日志显示“必须提供移动动作的位置”。

我想在Kitap,Müzik,Film,Oyun上访问n11.com网站,然后单击Kitap,但它不起作用。
谢谢

@Test

public void  startWebDriver(){
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.n11.com");


Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath(".//*[@id='contentMain']/div/nav/ul/li[8]/a"))).perform();


}

最佳答案

使用以下代码实现相同的目的-

    System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
    driver =new ChromeDriver();
    driver.get("http://www.n11.com/");
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    WebElement menu =  driver.findElement(By.xpath("//li[@class='catMenuItem']/a[@title='Kitap, Müzik, Film, Oyun']"));
    WebElement submenu = driver.findElement(By.xpath("//li[@class='subCatMenuItem']/a[@title='Kitap']"));

    Actions action = new Actions(driver);

    action.moveToElement(menu).moveToElement(submenu).click().build().perform();


使用一些Implicit Wait避免超时异常来查找您的Web元素
使用更具体的xpath查找您的Web元素。

对于您的情况,首先需要将鼠标悬停在Kitap, Müzik, Film, Oyun菜单上,然后必须单击Kitap子菜单

09-27 07:21