【发布时间】:2021-04-29 16:31:08
【问题描述】:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
class Main():
def Login(self,username,password):
self.username = username
self.password = password
driver = webdriver.Chrome()
driver.get("http://instagram.com")
time.sleep(5)
login_input = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input')
password_input = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input')
login_input.send_keys(self.username)
password_input.send_keys(self.password)
main = Main.Login("test","test")
问题是我收到此错误:TypeError: Login() missing 1 required positional argument: 'password'。
谁有解决方案?
【问题讨论】:
-
你必须在调用
Login之前实例化Main。试试:main = Main().Login('test', 'test') -
你必须先创建你的类的一个实例,然后调用方法才有意义。例如
Main().Login("test","test"),尽管您可能希望将Main()拆分为单独的赋值语句,以便稍后引用该实例。 -
这能回答你的问题吗? Missing 1 required positional argument: 'y'
标签: python