最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to click on an angularjs link using python selenium? - Stack Overflow

programmeradmin0浏览0评论

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()

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()
Share Improve this question edited Oct 10, 2015 at 6:55 Chris asked Oct 10, 2015 at 6:48 ChrisChris 5,83418 gold badges71 silver badges126 bronze badges 1
  • Are you getting any exception? – Saifur Commented Oct 12, 2015 at 3:23
Add a ment  | 

2 Answers 2

Reset to default 5

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()

Try using find elements by tagname or class and then click can be called. XPath approach always not useful.

Since multiple items exist, check generated html and use 'next' while writing script. Don't go by html code. Check generated html and try to find values.

发布评论

评论列表(0)

  1. 暂无评论