一尘不染

如何通过Selenium-Webdriver和Java使用Java进行鼠标悬停

selenium

尝试自动化门户网站http://demo.nopcommerce.com/时,无法在“电子设备”菜单上选择鼠标悬停,然后选择“相机和照片”子菜单。相同地使用以下脚本。

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();

阅读 310

收藏
2020-06-26

共1个答案

一尘不染

Mouse Hover 结束 "Electornics" 菜单并选择 "Camera& Photo",可以使用以下代码块:

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.");
2020-06-26