0
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")

The problem is that I am getting this error: TypeError: Login() missing 1 required positional argument: 'password'. Anyone have solution?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
ctrlshifti
  • 31
  • 5
  • 2
    You have to instantiate `Main` before calling `Login`. Try: `main = Main().Login('test', 'test')` – James Jan 25 '21 at 20:35
  • 1
    You have to create an instance of your class before it's even meaningful to invoke methods. `Main().Login("test","test")` for example, although you probably want to split the `Main()` off into a separate assignment statement, so that you have a reference to the instance later. – jasonharper Jan 25 '21 at 20:36
  • Does this answer your question? [Missing 1 required positional argument: 'y'](https://stackoverflow.com/questions/63085582/missing-1-required-positional-argument-y) – Gino Mempin Jan 25 '21 at 23:09
  • Does this answer your question? [TypeError: Missing one required positional argument](https://stackoverflow.com/q/50594441/2745495) – Gino Mempin Jan 25 '21 at 23:10

2 Answers2

3
main = Main.Login("test","test")

Should be:

main = Main().Login("test","test")

or:

main = Main()
main.Login("test","test")
eatmeimadanish
  • 3,809
  • 1
  • 14
  • 20
1

Your method isn't a class method, so you can't access it with Main.Login. Add a @classmethod decorator to your function or create first an instance of Main and call your method on that instance.

Plus, your function doesn't return anything, so assigning it to a variable will just give you None.

JeroSquartini
  • 347
  • 1
  • 2
  • 11