我对Python和Selenium还比较陌生,但我已经开始学习了。我一直在谷歌上搜索如何解决这个编码问题,但找不到确切的解决方案。在
我要做的是点击页面上的所有用户名链接,点击我要访问的页面上的follow按钮,然后返回到原始页面并对其余的用户名链接执行相同的操作。在
基本上,我想创建一个循环来执行此操作:单击第一个用户名
单击“跟随”按钮
返回上一页
单击第二个用户名
单击“跟随”按钮
返回上一页
等等。。。。。通过每个环节
以下是我目前的代码和我目前所做的尝试: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()
程序完成,屏幕上什么也没发生。也没有错误消息。在
我必须改变什么来点击初始页面上的每个链接,然后点击链接带我去的页面上的按钮?在
非常感谢你的帮助。在