从WebDriver下拉列表中选择一个项目

时间:2020-03-08 22:21:54

标签: selenium-webdriver

您需要在下拉列表中选择一个特定的项目。在此阶段,困难在于列表在单击时没有响应。

WebDriver,Selenium 3.141.59,谷歌浏览器

网站https://cloud.google.com/products/calculator 在“操作系统”项中,我需要选择“ Free .....” driver.switchTo()。frame(0);

driver.switchTo().frame("myFrame");

WebElement operatingSystem = new WebDriverWait(driver, 10)
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//md-select-value/span/div[contains(text(),'Free')]/../../..")));
operatingSystem.click();
WebElement checkFree = new WebDriverWait(driver, 10)
.until(ExpectedConditions.elementToBeClickable(By.xpath("//md-option/div[contains(text(),'Free')]/..")));
checkFree.click();

1 个答案:

答案 0 :(得分:0)

Select fruits = new Select(driver.findElement(By.id("subjects")));
    fruits.selectByVisibleText("maths");
    fruits.selectByIndex(1);

上面的代码在出现下拉菜单时必须运行正常。

相关问题