无法执行单击链接的鼠标悬停操作

时间:2017-05-10 10:36:05

标签: java mousehover

我正在使用www.flipkart.com,我想将鼠标悬停在" Appliances"并点击"电视"。

public static void main(String args[]) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver","C:\drivers\chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.get("http://www.flipkart.com");
    driver.manage().window().maximize();
    Thread.sleep(1000);
    WebElement mainMenu = driver.findElement(By.xpath("//a[@title='Appliances']"));
    WebElement submenuxpath = driver.findElement(By.xpath("//li[@class='Wbt_B2'][2]//li[@class='_1KCOnI _1h5QLb']//a[@title='Televisions']"));
    Actions builder = new Actions(driver);
    builder.moveToElement(mainMenu).perform();
    //builder.moveToElement(submenuxpath).click().perform();
    //driver.click(submenuxpath);
    Thread.sleep(1000);
    driver.close();
}

它可以将鼠标悬停在" Appliances"上。但我在driver.click(submenupath)builder.moveToElement(submenuxpath).click().perform()收到错误。我哪里错了? driver.click(submenupath)错误:对于WebDriver类型,未定义方法click(WebElement)。快速修复:向驱动程序添加强制转换即使我正在做添加演员,它也不起作用。对于builder.moveToElement(submenuxpath).click()。perform(),没有错误,但也没有点击。

0 个答案:

没有答案