【发布时间】:2019-03-04 14:30:15
【问题描述】:
仍然是 selenium 的新手,xpath 大部分时间都很好用,但在这种情况下不能使用下拉框从下拉框中选择元素:
盒子的xpath是:
//*[@id="select2-report_object-container"]
我让浏览器点击它,现在它显示一个选项下拉列表, 现在我想从列表中选择元素“标题”APP 7.08。
xpath 不起作用,因为它只显示容器
//*[@id="select2-report_object-container"]
要选择的元素如下:
<span class="select2-selection__rendered" id="select2-report_object-container" title="APP 7.08">APP 7.08</span>
标签名称不起作用,链接名称也可以,也尝试使用 id 然后是标题值
消息:
没有这样的元素:无法定位元素
我也试过了
selenium.select('//*[@id="select2-report_object-container"]' , title="APP 7.08";
运气不好。
我觉得我需要向初始 xpath 或 ID 添加第二个参数,但不确定使用什么来从 span 调用 APP 7.08 的值。
<span class="select2-selection__rendered" id="select2-report_object-container" title="APP 7.08">APP 7.08</span>
谁能帮忙?
【问题讨论】:
-
可以分享一下html代码吗?对于选择标签,您可以使用 getIndex()、getValue、getText 方法来获取您的值
-
这是可用的:在位置类的 html 中,值 17 是我需要的。
标签: python selenium select xpath drop-down-menu