Selenium错误:缺少1个必需的位置参数:'url'

时间:2019-01-24 21:06:01

标签: python-3.x selenium-chromedriver

我正在使用Python 3.7和chromedriver(2.45.615291)对Selenium(3.141.0)进行实验,并遇到以下错误。

TypeError: get() missing 1 required positional argument: 'url'.

主要代码:

from session import browser
from authentication import consolelogin as cl
from selenium.webdriver.firefox.options import Options
from selenium import webdriver

#select driver
driver = webdriver.Chrome

#define options for session
options = Options()
options.set_headless(False)
options.set_capability("pageLoadStrategy","none")
options.binary_location = "file_location" 

#create a session object
session = browser.session(driver=driver,options=options)
session.launch()

#login to google
Google = cl.GoogleLogin("https://accounts.google.com","username"
,"password",session.driver)
Google.UserLogin()

使用以下代码创建浏览器会话:

class session():
    def __init__(self,driver,options):
        self.__name = "BrowserSession"
        self.driver = driver
        self.options = options        

    def launch(self):
        driver = self.driver(options=self.options)
        return driver

然后使用该会话尝试登录:

class site():
    def __init__(self,url,username,password):
        self.url=url
        self.username=username
        self.password=password

class GoogleLogin(site):
    def __init__(self,url,username,password,session):
        site.__init__(self,url,username,password)
        self.session = session

    def UserLogin(self):
        now = self.session.get(self.url) #go to site
        #perform the login

有人能看到我在做什么吗?

1 个答案:

答案 0 :(得分:1)

您需要保存从session.launch()返回的初始化驱动程序,并将其传递到GoogleLogin而不是session.driver,后者仍然是尚未初始化的驱动程序:

driver = session.launch()

Google = GoogleLogin("https://accounts.google.com", "username", "password", driver)