Java 在selenium中未获得鼠标悬停测试脚本的预期结果
下面是鼠标悬停在元素上的代码片段Java 在selenium中未获得鼠标悬停测试脚本的预期结果,java,selenium,action,Java,Selenium,Action,下面是鼠标悬停在元素上的代码片段 public static void main(String[] args) throws InterruptedException { System.setProperty("Webdriver.ie.driver","D://IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(); driver.manage().timeouts().implicit
public static void main(String[] args) throws InterruptedException
{
System.setProperty("Webdriver.ie.driver","D://IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.amity.edu/");
String title = driver.getTitle();
System.out.println(title);
Actions action = new Actions(driver);
WebElement MainTab = driver.findElement(By.xpath("//div[@class='main']/ul[2]/li[2]/a"));
action.moveToElement(MainTab).build().perform();
}
试试下面的代码,它可以在chrome和firefox浏览器中使用 由于IE浏览器存在一些问题,Action类不能与IE浏览器一起使用 有关更多详细信息,请参阅此
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); //path for your browser.
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.amity.edu/");
String page_title = driver.getTitle();
System.out.println(page_title);
WebElement main_menu = driver.findElement(By.xpath("//ul[@class='megamenu main-nav']/li/a[text()='Campuses']")); // Get main menu
WebElement child_menu = driver.findElement(By.xpath("//ul[@class='megamenu main-nav']//li/a[text()='Chennai']")); // get Submenu called Chennai
Actions act = new Actions(driver);
act.moveToElement(main_menu).perform();
new WebDriverWait(driver, 60).until(ExpectedConditions.visibilityOf(child_menu)); //wait for element
act.moveToElement(child_menu).click().perform();
你可以分享url或html代码吗?你在尝试悬停时遇到了什么错误。如果堆栈溢出,通常会感谢你提供一些解释。请添加一些html代码并解释你得到了什么。它在chrome中工作,您使用哪个版本的IEI获取消息您正在使用不受支持的命令行标志-忽略证书错误。chrome浏览器发布后,稳定性和安全性将受到影响。而且URL也没有启动。获取以下异常:Hello Jainish,感谢您的回复。我收到一条消息,您正在使用不受支持的命令行标志-忽略证书错误。chrome浏览器发布后,稳定性和安全性将受到影响。而且URL也没有启动。我不知道到底是什么问题,因为对于我的应用程序,我能够成功地启动chrome浏览器。你能帮忙吗?请更新chrome驱动程序。并提供启动chrome浏览器的正确路径。如果您遇到与此问题相关的其他问题,请务必向我提供最新信息。你的问题解决了吗?如果对你有用,请将这个答案标记为已接受。