【发布时间】:2016-11-09 09:45:26
【问题描述】:
下面是一段代码,它表示一个下拉菜单。
我需要在此下拉列表中选择 Date 值,由<option value="1" label="Date">Date</option> 表示
<select id="type" class="text-input ng-pristine ng-valid ng-scope ng-touched" ng-style="cssStyle" name="type" ng-if="!options.hidePlaceholder" ng-model="result.type" qmx-observe-value="text" ng-disabled="options.readonly" ng-options="obj.value as obj.text group by obj.groupby for obj in selectData" style="font-size: 13px; opacity: 1; width: 100%;">
<option class="ng-binding" value="">----</option>
<option value="0" selected="selected" label="Text">Text</option>
<option value="1" label="Date">Date</option>
<option value="2" label="Numeric">Numeric</option>
<option value="3" label="Switch">Switch</option>
<option value="4" label="Map Location Marker">Map Location Marker</option>
<option value="5" label="Picker">Picker</option>
<option value="6" label="List">List</option>
</select>
以下方法无效。
1.) 通过导入 org.openqa.selenium.support.ui.Select
Select elm = new Select(driver.findElement(By.xpath(".//*[@id='type']/option[3]")));
elm.selectByVisibleText("Date");
控制台显示:
元素应该是“选择”但是“选项”
2.) 首先单击下拉菜单以显示要选择的选项,然后单击该选项。
driver.findElement(By.xpath(".//*[@id='type']")).click();
driver.findElement(By.xpath(".//*[@id='type']/option[3]")).click();
控制台显示:
DEBUG 元素缺少可访问的名称:id: type, tagName: 选择,类名:文本输入 ng-pristine ng-untouched ng-valid ng-范围
3.) 使用 JavascriptExecutor 获取点击。
driver.findElement(By.xpath(".//*[@id='type']")).click();
((JavascriptExecutor)driver).executeScript("arguments[0].click();", driver.findElement(By.xpath(".//*[@id='type']/option[3]")));
控制台显示:
DEBUG 元素缺少可访问的名称:id: type, tagName: 选择,类名:文本输入 ng-pristine ng-untouched ng-valid ng-范围
4.) 使用鼠标悬停在下拉选项中被选中,然后执行点击它。
driver.findElement(By.xpath(".//*[@id='type']")).click();
WebElement subdrop = driver.findElement(By.xpath(".//*[@id='type']/option[3]"));
Actions action = new Actions(drive);
action.moveToElement(subdrop).perform();
Custom.Twait();
action.click(subdrop).perform();
控制台显示:
线程“main”中的异常 org.openqa.selenium.UnsupportedCommandException: POST /session/a37a745a-e40c-45a9-9760-8e01b451a017/moveto 不匹配 已知命令(警告:服务器未提供任何堆栈跟踪 信息)
我还在使用此代码的位置添加了 Wait in Between。为了简单起见,我没有包括它。
需要帮助。
【问题讨论】:
标签: javascript java selenium