dropdown
在表格内。NOSUCHELEMENTEXCEPTION:无法在表格内找到下拉列表
这里是我的html代码:
<div class="table-responsive">
<table class="table notification-table">
<thead>
<tr>
<th>ITEM</th>
<th>PRODUCT CODE</th>
<th>WEIGHT</th>
<th>AVAIL</th>
<th>LOT NUMBER</th>
<th>STORE QTY</th>
<th>STORAGE LOC</th>
<th>STORAGE POINT</th>
<th/>
</tr>
</thead>
<tbody>
<tr>
<td>Chicken</td>
<td>AG0000</td>
<td>2Kg</td>
<td>5</td>
<td>57</td>
<td>5</td>
<td>
<div class="styled-select slate quantity">
<select id="stockLoc_66" class="cursor stockLocationListItem stockSelectItem selected" name="stockLoc_66">
<option value="">Select One</option>
<option value="Loc1">Loc1</option>
<option value="Loc2">Loc2</option>
<option value="Loc3">Loc3</option>
<option value="hgfhf">hgfhf</option>
<option value="123">123</option>
<option value="Loc 7">Loc 7</option>
</select>
</div>
</td>
<td>
<td>
</tr>
</tbody>
</table>
</div>
我的硒代码,找到并选择下拉菜单里面的表是:
WebElement allocationtable = driver.findElement(By.xpath(".//table[@class='table notification-table']"));
List<WebElement> rows = allocationtable.findElements(By.tagName("tr"));
for (WebElement eachrow : rows)
{
List<WebElement> columns = eachrow.findElements(By.tagName("td"));
for (WebElement eachcolumn : columns)
{
String elementtext = "STORAGE LOC";
String elementtext2 = "STORAGE POINT";
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='stockLoc_66']")));
Select storagelocation = new Select(driver.findElement(By.xpath(".//*[@id='stockLoc_66']")));
...
}
}
它得到一个NoSuchElementException
上
By.xpath(".//*[@id='stockLoc_66']")
我不明白为什么要使用XPath当你可以直接使用By.id()。 – SaiPawan
请发布一个链接到页面,以便我们可以看到完整的HTML。在这里你还没有描述的其他事情正在发生。哪一行有问题?你已经指出了一个位于多行的定位器。同时发布完整的异常消息。你有没有检查iframe等? – JeffC
页面上是否有多个元素与'id =“stockLoc_66”'? – JeffC