面对Selenium WebDriver选择功能的问题

时间:2014-05-28 10:35:48

标签: selenium-webdriver

在自动化流程中,我的脚本正确识别Dropdown对象,并根据传递的值进行选择。

public NewV1ProjectPage selectResponsiblePerson(String responsiblePersonValue){
    WebElement responsiblePerson = (new WebDriverWait(driver, 10))
              .until(ExpectedConditions.presenceOfElementLocated(By.name("responsible_person_sap_id")));
    new Select(responsiblePerson).selectByVisibleText(responsiblePersonValue);
    return this;
}

但问题是当它移动到下一个下拉列表时,一旦它移动到新的下拉列表,就会取消选择上一个下拉列表中选择的值。

我不确定是什么导致该值从此下拉列表中消失,所有下拉列表都正常工作...

请有人帮忙!!!

1 个答案:

答案 0 :(得分:0)

尝试以下代码可能对您有所帮助,

WebElement element = driver.findElement(By.id(""));
Select sortby = new Select(element);
List<WebElement> options =sortby.getOptions();
for (WebElement element1 : options) {
    // given the value in data place
if (element1.getText().equals(data)) {
         element1.click();
     Thread.sleep(5000);
    }
}
相关问题