隐藏标记的选择问题

时间:2017-10-10 09:13:38

标签: selenium

我无法访问此选项中的选项。

<tooltip-component params="id:'title1',title:'Alert name should be unique',isImportant:true"></tooltip-c
<br>
<select class="chosen-select" data-placeholder="Alert Type" id="alert_type" data-bind="options:alertType,optionsText: 'name', optionsValue: 'id',chosenSelectedOptions: selected Alert,valueAllowUnset: true" ></select>

如何使此下拉列表可见且可访问?

2 个答案:

答案 0 :(得分:0)

您可以使用ID找到它,尝试此代码

    Select dropdown= new Select(driver.findElement(By.id("alert_type")));
    dropdown.selectByVisibleText("Value under Dropdown");.

您也可以使用xpath

    Select dropdown= new Select(driver.findElement(By.xpath("//*[@id='alert_type']")));
    dropdown.selectByVisibleText("Value under Dropdown");

答案 1 :(得分:0)

尝试以下任何一种答案。

new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("alert_type")));
new Select(driver.findElement(By.id("alert_type"))).selectByVisibleText("Text Name Under Your Dropdown");
  

OR

new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("alert_type")));
new Select(driver.findElement(By.id("alert_type"))).selectByIndex(0);  //Indexing start from zero
  

OR

new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("alert_type")));
new Select(driver.findElement(By.id("alert_type"))).selectByValue("Value Name Under your Dropdown");