我们如何在子菜单

时间:2017-05-10 10:19:19

标签: selenium selenium-webdriver

场景:

  1. 我有一个链接,链接名称是'订单'
  2. 鼠标悬停时显示下拉列表,下拉列表中有一些值,如加入,dos管理,实验室管理等。只有在悬停鼠标后才会显示值。
  3. 现在我要从此下拉菜单中选择“加入”值。
  4. enter image description here 请点击子菜单

3 个答案:

答案 0 :(得分:0)

这是使用Actions类'来处理的。硒中的moveToElement()方法;

WebElement orders=driver.findElement(By.xpath("\\xpath\to\your\orders\element"));
WebElement Accessioning=driver.findElement(By.xpath("\\xpath\to\your\orders\element"));

action.moveToElement(orders).moveToElement(Accessioning).build().perform();

<强>更新:

driver.manage().window().maximize();

        driver.get("http://biotdev.technossustest.com/Workflow/Worklist2.aspx");

        driver.findElement(By.cssSelector("#ctl00_LoginContent_MainLogin_UserName")).sendKeys("hmeyer");
        driver.findElement(By.cssSelector("#ctl00_LoginContent_MainLogin_Password")).sendKeys("spivulet");

        driver.findElement(By.cssSelector("#ctl00_LoginContent_MainLogin_LoginImageButton")).click();

        Thread.sleep(10000);
        driver.findElement(By.cssSelector("#ctl00_PassowrdChangeNotification_OkPushButton")).click();

        Thread.sleep(10000);
        Actions action = new Actions(driver);
        WebElement menuItem = driver.findElement(By.cssSelector("#ctl00_MainMenun5 > table"));
        WebElement subMenu = driver.findElement(By.cssSelector("#ctl00_MainMenun23 > td > table > tbody > tr > td > a"));


        action.moveToElement(menuItem).build().perform();
        Thread.sleep(5000);
        action.moveToElement(subMenu).click().build().perform();

答案 1 :(得分:0)

我已经尝试了这个并且已经解决了,谢谢Kushal的帮助。

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("ctl00_DefaultContent_WorklistCtrl_WorklistTable")));

WebElement menu = wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@id='ctl00_MainMenun5']//td[2]"))));     
Actions action = new Actions(driver);


action.clickAndHold(menu).build().perform();
WebElement item = driver.findElement(By.xpath("//*[@id='ctl00_MainMenun23']//a[text()='Accessioning']"));
item.click();

答案 2 :(得分:0)

尝试使用Robot类......

Point coordinates = driver.findElement(By.xpath/id(xpathString/id)).getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates.getX(),coordinates.getY());

以上代码不适用于无头环境。

相关问题