我試圖為Selenium找到一種合適的方法來選擇select-box中的一個專案。
我已經嘗試使用:
new Select(driver.findElement(By.xpath("//select-box[@name='countryCode']")).selectByVisibleText(country)。
但得到的預期錯誤是:
org.openqa.selenium.support.ui.UnexpectedTagNameException。元素應該是 "select",但卻是 "select-box"
嘗試使用WebElement可以很好地選擇元素,但無法在結果中 "搜索 "到正確的專案串列。
<select-box name="type" options="$ctrl.ClubTypes"
track-by="value" label-by="label" required="">
<div class="SelectBox">
<div>
<div></div>
<input readonly="" class="Input " type="text" value="Club">
</div>
<ul class="SelectBox-options ng-scope" ng-if="$ctrl.isShowingOptions" style="">
<li>國家串列專案</li>
</ul>
</div>
</select-box>
我是使用Selenium和一般編程的新手,所以任何幫助都是非常好的。
uj5u.com熱心網友回復:
代替
new Select(driver.findElement(By.xpath("//select-box[@name='countryCode']")).selectByVisibleText(country) 。)
只要試試
String contry = "IRAN";
driver.findElement(By.xpath("//div[@class='SelectBox']").findElement(By.xpath(".//li[包含(text(),'" country "')]" )
uj5u.com熱心網友回復:
這個例外
org.openqa.selenium.support.ui.UnexpectedTagNameException。元素本應是 "select",但卻是 "select-box"
基本的意思是,你試圖使用Select類從Selenium,(這是僅用于drop downs建立使用Select和option標簽)。
如果你注意你所分享的HTML,沒有任何Select,而是select-box
解決方案 :
代碼試驗1 :
Thread.sleep(5);
driver.findElement(By.xpath("//select-box[@name='countryCode']").click()。
代碼試用2 :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//select-box[@name='countryCode']")) .click()。
使用其中任何一個,它將點擊下拉,然后你可以用類似的方式選擇你想要的選項。
我需要先看一下outerHTML,以便找到可靠的定位器來點擊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/327061.html
標籤:
上一篇:這是升級標準庫鎖的有效方法嗎?
