2017-10-10 53 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。等待使用'顯式等待'方法。我也更新了我的答案。 –