如何使用selenium webdriver(eclipse)单击下拉列表(不是由select创建的)?

问题描述 投票:0回答:1

我尝试在下一页的“付款方式”中选择下拉值。

登录https://my.orderhive.com/

重定向到https://my.orderhive.com/orders >>点击“新订单”按钮

在此页面上,“付款方式”下拉列表。我想为该下拉列表选择“Check”值。

我试图选择使用链接文本,XPath,选择和操作。但是,他们都没有工作。

Actions a = new Actions(driver);
WebElement b = driver.findElement(By.xpath("//[@id=\"footerAction\"]/span"));
a.moveToElement(b).click().perform();

Click Here to See Image

selenium testing selenium-webdriver automated-tests qa
1个回答
2
投票

使用以下代码:

WebDriverWait wait =new WebDriverWait(driver,10);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[normalize-space()='Payment Method']//following-sibling::div")));
driver.findElement(By.xpath("//label[normalize-space()='Payment Method']//following-sibling::div")).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='PaymentMethod']//div[@id='footerAction']")));
List<WebElement>options= driver.findElements(By.xpath("//div[@id='PaymentMethod']//div[@id='footerAction']"));

    for (WebElement option : options){
        if (option.getText().equals("Cheque")){
            option.click();
            break;
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.