您好我无法找到以下dropdown元素。这是HTML代码:
<div class="FormDetails"><br>
<ul class="lsn"><br>
<li><br>
<span id="errfileName"></span><br>
</li><br>
<li style="display: block;"><br>
<div class="LeftSection-Form" style="margin-bottom: 15px;"><br>
<div class="FormLabel"><br>
<Community<br>
<span class="FormDetails_required"> Required</span><br>
</div><br>
<div class="FormValue"><br>
<select id="Fact-Communities-LIVE" class="ToolTipPopup Sel1355" tooltip-title=<p>"Community "</p> onkeydown="return preventBackspace(event);" <br>onchange="dropDownValue(this);" name="Fact.Communities.LIVE" emptyoption="-Please select-"><br>
<option value="TxnyD.PleaseSelect.1.1">-Please select-</option><br>
<option value="TxnyD.Communities.1.1">UVDB</option><br>
<option value="TxnyD.Communities.2.1">THQS</option><br>
<option value="TxnyD.Communities.3.1">Master</option><br>
<option value="TxnyD.Communities.4.1">Connexio</option><br>
<option value="TxnyD.Communities.5.1">SL</option><br>
<option value="TxnyD.Communities.6.1">OG</option><br>
<option value="TxnyD.Communities.7.1">UT</option><br>
<option value="TxnyD.Communities.8.1">TR</option><br>
<option value="TxnyD.Communities.9.1">FGW</option><br>
<option value="TxnyD.Communities.10.1">E.ON TSMS</option><br>
<option value="TxnyD.Communities.11.1">Vattenfall TSMS</option><br>
<option value="TxnyD.Communities.12.1">Delivery1</option><br>
<option value="TxnyD.Communities.13.1">Test community</option><br>
<option value="TxnyD.Communities.14.1">Automotive</option><br>
<option value="TxnyD.Communities.15.1">SHELL SUPPLIER QUALIFICATION SYSTEM</option> <br>
<option value="TxnyD.Communities.17.1">Nestle</option><br>
<option value="TxnyD.Communities.18.1">BuildingConfidence</option><br>
</select><br>
</div><br>
</div><br>
我尝试使用以下脚本来查找这些元素:
//driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']")).click();
//driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]/text()='SHELL SUPPLIER QUALIFICATION SYSTEM'")).click();
也尝试过这些:
//driver.findElement(By.id("Fact-Communities-LIVE")).sendKeys("SHELL SUPPLIER QUALIFICATION SYSTEM");
//Thread.sleep(1000);
//new Select(driver.findElement(By.id("Fact-Communities-LIVE"))).selectByVisibleText("SHELL SUPPLIER QUALIFICATION SYSTEM");
&安培;这些也是
//WebElement dropDown = driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']"));
//List<WebElement> options = dropDown.findElements(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]/text()"));
//driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]")).click();
但似乎出了点问题..请任何人指导我这些。
答案 0 :(得分:1)
尝试以下代码
WebElelment dropDown = driver.findElement(By.id("Fact-Communities-LIVE"));
new Select(dropDown).selectByVisibleText("SHELL SUPPLIER QUALIFICATION SYSTEM");
or
new Select(dropDown).selectByValue()("TxnyD.Communities.15.1");
答案 1 :(得分:0)
使用Select class:
Select select = new Select(driver.findElement(By.Id("Fact-Communities-LIVE");
然后使用您想要选择的选项,按值,按文本,按索引等选择。 如果所有标签都正确打开和关闭,也要检查html上的所有标签