【问题标题】:How to mouse hover using java through selenium-webdriver and Java如何通过 selenium-webdriver 和 Java 使用 java 鼠标悬停
【发布时间】:2018-04-25 22:38:26
【问题描述】:

在尝试自动化门户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();

【问题讨论】:

    标签: java selenium selenium-webdriver webdriver selenium-chromedriver


    【解决方案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.");
    

    【讨论】:

      猜你喜欢
      • 2013-01-19
      • 2013-06-22
      • 1970-01-01
      • 2013-09-22
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多