title: How to Click on all "role=button" on a webpage using selenium and python
body: <p>I'm trying to create my first project using python and Selenium, and i'm new into it, it's just a simple project that ask user for his/her facebook username and password, then login redirect to the facebook.com/user/following page and unfollow everybody the user is following.</p>
  
  <p>Here's my code bellow</p>
  
  <p>I imported the necessary modules using this codes </p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  import selenium
  import time
  </code></pre>
  
  <p>I closed the Facebook popup Notification to avoid disruption of the code..</p>
  
  <pre><code>##SHUTTING POPUP NOTIFICATION
  chrome_options = webdriver.ChromeOptions()
  prefs = {"profile.default_content_setting_values.notifications": 2}
  chrome_options.add_experimental_option("prefs", prefs)
  chrome_options.add_argument("start-maximized")
  chrome_options.add_argument("start-maximized")
  driver = webdriver.Chrome(chrome_options=chrome_options)
  </code></pre>
  
  <p>Defined a Login <code>func</code> that takes username and pass word after opening facebook..</p>
  
  <pre><code>  def login():
          #Login
          user = input('Whats your username or email    ')
          passw = input('Input your password    ')
          driver.get("https://www.facebook.com/")
          username = driver.find_element_by_name("email")
          username.send_keys(user)
          password = driver.find_element_by_name("pass")
          password.send_keys(passw)
          password.send_keys(Keys.RETURN)
  </code></pre>
  
  <p>Next I just created a 3 sec. Time function</p>
  
  <pre><code>  def timeToSleep():
       time.sleep(3)
  </code></pre>
  
  <p>The getPage function is the function for redirecting to my destination i.e User following</p>
  
  <pre><code>  def getPage():
          ##Get Page
          driver.get("https://www.facebook.com/Username/ID/following")
  </code></pre>
  
  <p>This is the click function to click on the places i want and this is where my problem is..
  I will like to start clicking on all following with the click funcion bellow..
  [Check img]</p>
  
  <pre><code>  def click():
          xpath = "//a[@role='button']"
          a=driver.find_elements_by_xpath(xpath)
          for posts in a:
                posts.click()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4CaxE.png" rel="nofollow noreferrer">CLICK ON FOLLOWING</a></p>
  
  <p>But my problem now is this (The following button doesn't have any class or id except for an anchor attribute "role='button')..</p>
  
  <p>The code would have worked fine but they are other elements on the webpage with same role='button' attribute, like the pix below:
  <a href="https://i.stack.imgur.com/oV96r.png" rel="nofollow noreferrer">Toolbar</a>
  The facebook toolbars have same role button stuff..
  My question is this :
  How do i make Selenium skip the toolbar and start clicking from the Following buttons..</p>
  
  <p>So Sorry if my explanation is bad...
  I'll gladly appreciate any help from any body..</p>
  
  <p>Thanks in Advance</p>