2017-10-10 56 views
-3

我无法访问此选择选项。隐藏标记的选择问题

<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> 

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

+0

使用ID来访问一次它 – iamsankalp89

回答

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"); 
+0

TRY矿山请分享如果可能的话 – iamsankalp89

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"); 
+0

我已经尝试了所有网址的因此我在这里登陆...... :( – Aitori

+0

谢谢@耆那教。这是我得到的回应: 线程“main”中的异常org.openqa.selenium.ElementNotVisibleException:元素不可见:元素当前不可见并且可能不会被操纵 (会话信息:chrome = 61.0.3163.100) (Driver info:chromedriver = 2.29.461591(62ebf098771772160f391d75e589dc567915b233),platform = Windows NT 6.1.7601 SP1 x86)(警告:服务器没有提供任何堆栈跟踪信息) 命令持续时间或超时:2.31秒 构建信息:版本:'unknown' ,修订版:'1969d75',时间:'2016-10-18 09:43:45 -0700' – Aitori

+0

从你上面提到的错误,试着等待几秒钟后才能到达这个元素。所以你的司机可能会找到webelement。等待使用'显式等待'方法。我也更新了我的答案。 –