如何从“ mdb-select”列表中选择选项

时间:2019-12-30 14:05:03

标签: java selenium selenium-webdriver automated-tests

因此,我尝试使用以下代码从类型mdb-select的列表中选择一个选项:

Select dropdown = new Select(driver.findElement(By.id("selectEntidaBancaria")));

dropdown.selectByVisibleText("Davivienda S.A.");

但是Java向我显示了以下错误:

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "mdb-select"

您可以使用哪种方法从该类型的列表中选择一个选项?

1 个答案:

答案 0 :(得分:0)

因此,由于您的列表不是标准选择,因此Selenium Select失败。相反,您应该能够执行以下操作。

driver.findElement(By.id("selectEntidaBancaria")).click(); //click on the list to bring up choices

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//mdb-select[contains(.,'Davivienda S.A.')]")); //wait for dropdown to appear and be clickable

driver.findElement(By.xpath("//mdb-select[contains(.,'Davivienda S.A.')]")).click(); // and click on it

改编自Selenium tests are not able to interact with any of the elements的Python答案