Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click on an angularjs link using python selenium?

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()
like image 617
Chris Avatar asked Sep 27 '22 13:09

Chris


1 Answers

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()
like image 147
JeffC Avatar answered Sep 30 '22 08:09

JeffC