如何使用python selenium点击angularjs链接? [英] How to click on an angularjs link using python selenium?

查看:207
本文介绍了如何使用python selenium点击angularjs链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下html,其中多个链接使用相同的类和元素,我想点击使用python selenium的ng-switch-when =next的链接。

I have the following html with multiple links that use the same class and elements, and I'd like to click on the link that has ng-switch-when="next" with python selenium.

<a class="ng-scope" ng-switch-when="prev" ng-click="params.page(page.number)" href="">«</a>
<a class="ng-scope" ng-switch-when="first" ng-click="params.page(page.number)" href=""><span class="ng-binding" ng-bind="page.number">1</span></a><
<a class="ng-scope" ng-switch-when="next" ng-click="params.page(page.number)" href="">»</a>

这是我尝试过的,但网页没有回应。

This is what I've tried, but there is no response from the webpage.

driver.find_element_by_xpath("//a[@class='ng-scope'][@ng-switch-when='next']").click()


推荐答案

我知道你说你尝试过使用CSS类,但这应该与提供的HTML一起使用。如果没有,请发布更多相关的周边HTML,以便我可以调整CSS选择器。

I know you said you tried using CSS classes but this should work with the HTML provided. If it doesn't, please post more of the relevant surrounding HTML so I can adjust the CSS selector.

driver.find_element_by_css_selector("a[ng-switch-when='next']").click()

这篇关于如何使用python selenium点击angularjs链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆