如何通过 selenium-webdriver 和 Java 使用 java 鼠标悬停 [英] How to mouse hover using java through selenium-webdriver and Java

查看:25
本文介绍了如何通过 selenium-webdriver 和 Java 使用 java 鼠标悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试自动化门户 http://demo.nopcommerce.com/ 时,我无法选择鼠标悬停在电子"菜单上,然后选择相机和照片"子菜单.使用下面的脚本.

While trying to automate the portal http://demo.nopcommerce.com/, am not able to select mouse hover over "Electornics" menu and select "Camera & Photo" sub menu. Used the below script for the same.

WebElement electronic_Pdts = driver.findElement(By.xpath("//*[@class='title']//*[@title='Show products in category Electronics']"));
action.moveToElement(electronic_Pdts).build().perform();
driver.findElement(By.xpath("//*[@src='http://demo.nopcommerce.com/images/thumbs/0000006_camera-photo_450.jpeg']")).click();

推荐答案

鼠标悬停"Electornics"strong> 菜单并选择 "Camera & Photo" 您可以使用以下代码块:

To Mouse Hover over "Electornics" menu and select "Camera & Photo" you can use the following code block :

driver.get("http://demo.nopcommerce.com/");
Actions act = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement electronics = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li/a[@href='/electronics']")));
act.moveToElement(electronics).perform();
WebElement camera_n_photo = driver.findElement(By.xpath("//li/a[@href='/electronics']//following::ul/li/a"));
camera_n_photo.click();
System.out.println("Camera & photo Clicked.");

这篇关于如何通过 selenium-webdriver 和 Java 使用 java 鼠标悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆