0

The button is the "View All Suggestions" Button.

So I need to write line like:

browser.find_element_by_css_selector("something here").click()

And it doesn't have to be by css. This is just an example. Any method that words will do.

3
  • Please don't post screenshots of code. Take a look at selenium-python.readthedocs.io/locating-elements.html. It highlights some locator methods that should suit you (e.g. find_element_by_id or find_element_by_class_name). Commented May 3, 2019 at 0:23
  • Is there a reason you have to select the element by its css? There are other ways to select an element, such as by html tag type, html id, visible text, and so on. Commented May 3, 2019 at 2:10
  • @JohnGordon there is no restriction on how to select the element. it could be css or other methods. If you know how using other methods, then please submit an answer Commented May 3, 2019 at 2:13

1 Answer 1

2

To click on the first occurrence, use this:

browser.find_element_by_xpath('//a//*[contains(text(),"View All Suggestions")]').click()

To click on n-th occurrence, use this:

elements = browser.find_elements_by_xpath('//a//*[contains(text(),"View All Suggestions")]')
elements[3].click() # <-- Click on the 3rd occurrence if it exists.`
Sign up to request clarification or add additional context in comments.

6 Comments

Didn't work. selenium.common.exceptions.NoSuchElementException
Can you paste the HTML code? That will help us greatly :)
I don't know how to do that. Isn't that is what I have in the picture?
I've added another picture
I've updated my solution. It will click on the first occurrence of "View All Suggestions". If you need to click on the other occurrences you will need to use .find_elements_by_xpath() to store all occurrences in a list and click on the one that you want.
|

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.