好的,这句话给了我一个错误:
new Select(driver.findElement(By.id("870"))).selectByVisibleText(reason);
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"870"}
命令持续时间或超时:1.02秒
我已经尝试通过xpath和id找到它,并且我知道它的id为870.我已经尝试进入睡眠以确保它也被加载。
提前致谢。
我在Firefox上使用2.5版。
元素是
<select id="870" class="ui-widget-content reactor alias_reason" data-bind="options: questionValueGroup.questionValues, optionsText: 'qu…: properties(), setSingleSelected: $parent.providerAnswers()" paid="37" group="6" style="background-color: #FCFDFD;"></select>
编辑2:我想出了伙计们,我只是使用了chromes xpath选择器工具,它给了我一个不同的xpath。
答案 0 :(得分:0)
我认为你有一个以数字开头的id的事实让Selenium感到困惑。 W3C标准说Ids不能以数字开头,因此请尝试以下方法;
new Select(driver.findElement(By.css("[id='870']"))).selectByVisibleText(reason);
或
new Select(driver.findElement(By.xpath("//*[@id='870']"))).selectByVisibleText(reason);