当我尝试从文本框中获取值时,它抛出“没有找到这样的元素”问题,
以下是我的字段属性:
input id="altid" class="firstColumnInput text C1 disabled" type="text" value="100281" securityidpath="MEMBER_DEMOGRAPHICS.INDICATIVE_INFORMATION.INDICATIVE_INFORMATION.PERSON.ALT_IDENTIFIER" name="$EntryField$7" lockrequired="true" tabindex="-1" readonly="readonly"
获取值的代码是:
driver.findElement(By.xpath(OR.getProperty(object))).getAttribute("value");
结果:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id=\"age\"]"} For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.2.0', revision: '13073', time: '2011-07-25 19:23:22' System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_22' Driver info: driver.version: EventFiringWebDriver
请建议我如何解决此问题。
最佳答案
尝试使用 xpath 和输入的 id 进行搜索,例如:
driver.findElement(By.xpath("//*[@id=\"altid\"]")).getAttribute("value");
关于selenium - Selenium RC 中发生异常 : org. openqa.selenium.InvalidSelectorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8502283/