5

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()
1
  • Are you getting any exception? Commented Oct 12, 2015 at 3:23

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

1 Comment

This solution helped a lot!
-1

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.

2 Comments

i did try that but the issue is that the html has multiple links using the same tagnames and classes.
This is really a comment, not an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.