【发布时间】:2021-06-08 09:44:23
【问题描述】:
问题:我尝试从下拉列表中选择一个元素
我有一个包含以下 HTML 代码的下拉列表:
<span class="wpcf7-form-control-wrap localitate">
<select name="localitate" class="wpcf7-form-control wpcf7-select form-control" id="cf_location_trigger" aria-invalid="false">
<option value="">Locatie</option>
<option value="Bucuresti CARAMFIL">Bucuresti CARAMFIL</option>
<option value="Bucuresti THE LIGHT">Bucuresti THE LIGHT</option>
<option value="Cluj-Napoca">Cluj-Napoca</option>
<option value="Iasi">Iasi</option></select></span>
我尝试使用以下 Java 代码选择元素但没有成功:
location.click();
WebDriverWait waits = new WebDriverWait(driver, 20);
waits.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"cf_location_trigger\"]"))).click();
Select dropdownLocation = new Select(driver.findElement(By.xpath("//*[@id=\"cf_location_trigger\"]")));
dropdownLocation.selectByIndex(3);
如何选择元素,我尝试增加等待的时间,我也尝试使用Thread.sleep (),但它仍然无法识别列表中的项目或dropdownLocation.selectByText("Bucuresti CARAMFI");
【问题讨论】:
标签: java selenium testing automated-tests