I'm fairly new to Python and Selenium, but starting to pick it up. I've been googling how to solve this coding issue, but can't find the exact solution.
What I'm trying to accomplish is click all of the username links on a page, click the follow button on the page that I'm taken to, then return to the original page and do the same for rest of the username links.
Basically, I want to create a loop that does this:
- click on the first username
- click on the follow button
- go back to the previous page
- click on the second username
- click on the follow button
- go back to the previous page
ETC..... through each link
Here is my current code and what I've tried so far:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('thewebpage')
search = browser.find_element_by_id('getSearch')
search.click()
search.send_keys('searchitem' + Keys.RETURN)
searchitem = browser.find_elements_by_class_name("name")[0]
searchitem.click()
#I am now on the page where it shows the users
#this is where I'm getting stuck
#here's the first code I tried
links = browser.find_elements_by_link_text("#/user/")
for link in links:
link.click()
follow = browser.find_element_by_class_name("followAction")
browser.back()
#here's the second code I tried
import selenium.webdriver.support.ui as UI
def test(self):
driver = self.driver
wait = UI.WebDriverWait(driver, 5000)
links = driver.find_elements_by_link_text("#/user/")
for link in links:
link.click()
follow = driver.find_element_by_class_name("followAction")
follow.click()
driver.implicityly_wait(5)
driver.back()
The program completes and nothing happens on the screen. No error message either.
What must I change to click each link on the initial page and click a button on the pages that the links take me to?
Here's a link to a similar issue. Loop through links using Selenium Webdriver (Python)
Your help is greatly appreciated.
browser.implicitly_wait(5)aftertextsave.write(text+"\n\n")line and check again?