使用Selenium了解类结构

时间:2019-05-26 13:41:36

标签: python selenium-webdriver drupal

我试图了解我在这里做错了什么,我在强迫自己使用更多类,但遇到了一个问题。

我设置了一个Drupal站点来测试Selenium,并认为我会从中学习一门课程,到目前为止,我有:

导入课程

from platform_drupal import Drupal

设置驱动程序

def driver_init(using_linux, proxy):
    options = Options()
    options.headless = False
    options.add_argument('start-maximized')
    options.add_argument('disable-infobars')
    options.add_argument('--disable-extensions')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--ignore-ssl-errors')
    if proxy == "0.0.0.0:00":
        print("[-] ======= PROXY DISABLED ...")
    else:
        print("[+] ======= USING PROXY: " + str(proxy) + " ...")
        options.add_argument('--proxy-server=%s' % proxy)
    if using_linux == True:
        return webdriver.Chrome("/usr/bin/chromedriver", chrome_options=options)
    else:
        return webdriver.Chrome("chromedriver.exe", chrome_options=options)

从文本文件中圈出网站并将其发送给班级

    driver = driver_init(False, "")
    input_file = open("links\\linksTo[R]Page.txt", "r")
    for each_line in input_file:
        try:
            Drupal.login(driver, each_line.rstrip('\n'))
        except Exception as e: 
            print("REGISTRATION ERROR: ", e)

课程文件内容

from selenium.webdriver.support.ui import Select

class Drupal:

    def __init__(self, driver):
        self.driver = driver
        self.url = url

    def login(self, driver, url):
        driver.get(url)
        driver.find_element_by_id("edit-mail").click()
        driver.find_element_by_id("edit-mail").clear()
        driver.find_element_by_id("edit-mail").send_keys("EMAIL")
        driver.find_element_by_id("edit-field-first-name-und-0-value").click()
        driver.find_element_by_id("edit-field-first-name-und-0-value").clear()
        driver.find_element_by_id("edit-field-first-name-und-0-value").send_keys("FIRST_NAME")
        driver.find_element_by_id("edit-field-last-name-und-0-value").click()
        driver.find_element_by_id("edit-field-last-name-und-0-value").clear()
        driver.find_element_by_id("edit-field-last-name-und-0-value").send_keys("LAST_NAME")
        driver.find_element_by_id("edit-captcha-response").click()
        driver.find_element_by_id("edit-captcha-response").clear()
        driver.find_element_by_id("edit-captcha-response").send_keys("CAPTCHA")
        sleep(3)
        driver.find_element_by_id("edit-submit").click()

我一直在遇到类问题,所以我试图尽可能地学习,上面的代码在运行时会产生错误:

login() missing 1 required positional argument: 'url'

通过查看代码,我看不到任何明显的错误(无论如何我都可以看到),我错过了什么吗?任何帮助表示赞赏。

0 个答案:

没有答案