Selenium单击下一步按钮

2024-10-05 13:24:20 发布

您现在位置:Python中文网/ 问答频道 /正文

如何让selenium从下面的HTML代码中单击next按钮?在

<span class="action-btn" data-bind="visible: viewModel.page() < viewModel.pages(), click: viewModel.changePage(+1);">&gt;</span>

最初我写道:

^{pr2}$

但我注意到,在这个网站上,还有其他名字相似的{}。例如action-btn customize和{}

对于我当前的代码,它基本上只是点击action-btn customize,我的猜测是因为这个按钮名出现在我想要单击的代码之前。在

我应该如何编写代码呢?在

更新

这是画面的截图。黄色高亮显示是我要点击的。在

image of HTML code


Tags: 代码databindhtmlseleniumpageaction按钮
1条回答
网友
1楼 · 发布于 2024-10-05 13:24:20

看看你的屏幕截图,你想点击的action-btnpager类中的最后一个。在

而且,如果您只有一个div元素和pager类,那么可以选择其中的所有action-btn并得到最后一个:

elem = driver.find_element_by_css_selector("div.pager span.action-btn:last-of-type");

以下是有关^{}选择器的详细信息:

The :last-of-type CSS pseudo-class represents the last sibling with the given element name in the list of children of its parent element.

相关问题 更多 >

    热门问题