【问题标题】:Mouse hover not working in Selenium Webdriver鼠标悬停在 Selenium Webdriver 中不起作用
【发布时间】:2015-04-02 21:01:40
【问题描述】:

我正在尝试在 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();

【问题讨论】:

  • 错误是什么?您期望的操作与实际执行的操作是什么?请附上截图。 How to Ask

标签: java selenium


【解决方案1】:

请检查 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();

【讨论】:

  • 即使这个 xpath 是错误的,它也应该为以下代码显示扩展菜单 - WebElement eleFirstLevel=driver.findElement(By.xpath("//a [@href='/ci/engine /match/index.html?view=live']")); action.moveToElement(eleFirstLevel).perform();这也行不通..
猜你喜欢
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多