【问题标题】:How to handle the modules which are under the same menu by using single xpath expression for all the modules如何通过对所有模块使用单个 xpath 表达式来处理同一菜单下的模块
【发布时间】:2021-11-20 18:53:04
【问题描述】:

this is the example from our application

我正在尝试此代码但无法正常工作

WebElement ele=driver.findElement(By.xpath("//a[@title='Menu for Distribution']"));
        Actions act=new Actions(driver);
        act.moveToElement(ele).perform();
        Thread.sleep(3000);
        for (int i=3; i<=10; i++)
        {
            System.out.println(i);
            ele1=driver.findElement(By.xpath("//a[@target='frame_main'])[i]"));
            ele1.click();
        }
    

【问题讨论】:

  • 你能分享一个指向那个页面的链接和你所有的相关代码吗?
  • 你能解释一下你想要达到的目标吗?

标签: selenium-webdriver automation automated-tests


【解决方案1】:

请使用以下方法点击子菜单选项,

通过调用clickSubMenu("New Consignee");

public void clickSubMenu(String optionName){
    By mainMenu = By.xpath("//a[@title='Menu for Distribution']");
    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(mainMenu));
    action.build().perform();
    
    By subMenu = By.xpath("//a[text()='"+optionName+"']");
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(subMenu));
    driver.findElement(subMenu).click();
}

步骤:

  1. 将鼠标悬停在主菜单上
  2. 等待可见性
  3. 点击子菜单

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 2021-11-02
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    相关资源
    最近更新 更多