【发布时间】:2019-05-04 23:58:40
【问题描述】:
在网页中,我有以下元素:
....
<select class="widget-listbox form-control" size="6" multiple="multiple">
<option data-value="sIPSCs%20from%20juvenile%20(P21-30)%20C57BL%2F6J%20male%20mice%20hippocampus%20CA1%20pyramidal%20cell%20(A1)" value="sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)" class="">sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)</option>
<option data-value="sIPSCs%20from%20juvenile%20(P21-30)%20C57BL%2F6J%20male%20mice%20hippocampus%20CA1%20pyramidal%20cell%20(A2)" value="sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A2)" class="">sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A2)</option>
</select>
....
我正在尝试使用以下 xpath 表达式来选择第一个选项元素(用于 selenium 测试):
//option[contains(text(),"sIPSC")]
//option[text()="sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)"]
//option[@value="sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)"]
//select/option[contains(text(),"sIPSC")]
//select/option[text()="sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)"]
//select/option[@value="sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)"]
但没有显示任何结果(在 chrome 中,XPath Helper 版本 2.02;chrome 版本 70.0.3538.110)。我要查找的元素不在框架内。我还想选择 whole 字符串“sIPSCs from juvenile (P21-30) C57BL/6J male mice hippocampus CA1 pyramidal cell (A1)”,这可能是一个变量。随便一个字符串。我事先不知道这个字符串是什么样子的......
这次我做错了什么?上述任何表达都不应该起作用吗?
【问题讨论】:
-
至少第一个应该可以工作。你换框架了吗?显示您的代码
标签: selenium google-chrome selenium-webdriver xpath