鼠标悬停不在Selenium Webdriver中工作

时间:2015-04-02 11:39:34

标签: java selenium

我正在尝试在Cricinfo网站的菜单上执行鼠标悬停功能。

它没有抛出任何错误,也没有完成预期的操作。

任何人都可以建议我问题出在哪里,或者找到一种方法来调试它。

File file = new File(".\\Config\\Driver\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver = new ChromeDriver();
driver.get("http://www.espncricinfo.com/ci/engine/series/index.html?view=current");
driver.manage().window().maximize();
Thread.sleep(7000);
Actions action = new Actions(driver);
WebElement eleFirstLevel = driver.findElement(By.xpath("//a  [@href='/ci/engine/match/index.html?view=live']"));
action.moveToElement(eleFirstLevel).perform();
action.moveToElement(driver.findElement(By.xpath("//ul//li[3]"))).click().build().perform();
Thread.sleep(5000);
driver.quit();

1 个答案:

答案 0 :(得分:0)

请检查Xpath: -

action.moveToElement(driver.findElement(By.xpath("//ul//li[3]"))).click().build().perform();

检查此代码:

driver.get("http://www.espncricinfo.com/ci/engine/series/index.html?view=current");
driver.manage().window().maximize();
Thread.sleep(7000);
Actions action=new Actions(driver);
WebElement eleFirstLevel=driver.findElement(By.xpath("//a  [@href='/ci/engine/match/index.html?view=live']")); 
action.moveToElement(eleFirstLevel).perform();
action.moveToElement(driver.findElement(By.xpath(".//*[@id='nav_grp']/li[2]/div[2]/ul/li[3]"))).click().build().perform();
Thread.sleep(5000);
driver.close();