我使用的是 selenium-standalon-2.25.0 而 chrome 是 13 版。
这是html:
<select name="suffix" class="select">
<option value="" selected>Please select...</option>
<option value="Ms.">Ms.</option>
<option value="Mrs.">Mrs.</option>
<option value="Mr.">Mr.</option>
</select>
这是我调用以选择其中一个选项的命令。另一个是我从数据库中获取的变量,问题是我从数据库中获取的后缀。这适用于 Firefox 和 IE,但不适用于 chrome:
driver.findElement(By.xpath("//option[@value='" + other + "' and ..[@name='" + question + "']]")).click();
这是我得到的例外:
org.openqa.selenium.InvalidSelectorException: findElement execution failed;
Unable to locate an element with the xpath expression //option[@value='Ms.' and ..[@name='suffix']] because of the following error:
Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51 (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 52 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:08:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_25'
Driver info: driver.version: EventFiringWebDriver
Session ID: bf6368f23db4a2fe27d9b96849af1b1d
Command duration or timeout: 646 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-31-generic', java.version: '1.6.0_31'
Driver info: driver.version: RemoteWebDriver
Session ID: 134947044387
我已经为此工作了一段时间,我的猜测是与我的 findElement 语句有关。奇怪的是它适用于 FF 和 IE。任何帮助将不胜感激。再次感谢。
布莱恩