python selenium can可以单击多个Div,因为同一类
我正在尝试获得多个Div以在同一班级中获得单击,但这并不是那么有用 [SIT计划] [1] https://ibb.co/sfdt2lw
代码
<a href="javascript:void(0)" class="seat" title="[GHA-15]" data-toggle="tooltip" data-placement="bottom" onclick="chooseSeat(this)">0-4-5
<div class="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
</a>
<a href="javascript:void(0)" class="seat" title="[GHA-14]" data-toggle="tooltip" data-placement="bottom" onclick="chooseSeat(this)">0-2-5
<div class="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
</a>
这是我尝试的 **。但是只为单个Div工作** '''
div = driver.find_element_by_class_name("spinner")
div.click()'''
This is what i tried from Web. but is'nt helping
'''
div1 = driver.find_elements_by_xpath('//a[@class="seat"]//preceding-sibling::td[@div="spinner"]')
# div1.click()
'''
I am trying to achieve multiple div to get a click in the same class but it's ain't so helpful
[Sit Plan][1]
https://ibb.co/SfdT2LW
This is the code
<a href="javascript:void(0)" class="seat" title="[GHA-15]" data-toggle="tooltip" data-placement="bottom" onclick="chooseSeat(this)">0-4-5
<div class="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
</a>
<a href="javascript:void(0)" class="seat" title="[GHA-14]" data-toggle="tooltip" data-placement="bottom" onclick="chooseSeat(this)">0-2-5
<div class="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
</a>
**That's how I tried . but work for single div only **
'''
div = driver.find_element_by_class_name("spinner")
div.click()'''
This is what i tried from Web. but is'nt helping
'''
div1 = driver.find_elements_by_xpath('//a[@class="seat"]//preceding-sibling::td[@div="spinner"]')
# div1.click()
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要区分
0-4-5
和0-2-5
您可以简单地使用标题属性
(xpath
)来自共享HTML。应表示
0-4-5
// a [@title ='[gha-14]']
for0-2-5
单击就像:
或
更新:
有多种单击旋转器元素的方法。
使用
xpath-indexing:
或
使用
find_elements
或
等。
单击循环:
进口:
to differentiate between
0-4-5
and0-2-5
you can simply use thetitle attribute
(xpath
) from the shared HTML.should represent
0-4-5
//a[@title='[GHA-14]']
for0-2-5
Click it like:
or
Update:
There are multiple ways to click on the spinner element.
Use
XPath-indexing:
or
Use
find_elements
or
etc.
click in a loop:
Imports:
使用以下方式,您可以选择所需的div当多个DIV具有相同的类名称
此类名称是Div类的名称,索引是Div的索引,您想选择它从1到开始
Using following way you can select the required div when the multiple div have the same class name
Here class name is the name of div class and the index is the index of div which you want to select it start from 1 to onward
使用同一类获取所有元素:
然后在列表中迭代以获取您要寻找的东西
get all element with same class using:
then iterate through the list to get what you are looking for