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
    
Are you getting any exception? – Saifur Oct 12 '15 at 3:23
up vote 1 down vote accepted

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()
share|improve this answer

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.

share|improve this answer
    
i did try that but the issue is that the html has multiple links using the same tagnames and classes. – Chris Oct 10 '15 at 6:56
    
This is really a comment, not an answer. – JeffC Oct 18 '15 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.