Search code examples
pythonseleniumselenium-webdriverselenium-chromedriverwebautomation

How do I identify this button using python selenium?


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.


Solution

  • 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.`