Answer the question
In order to leave comments, you need to log in
Why are self functions needed here and why don't they work?
I'm new to python, I don't fully understand why the author of the video used the self functions
Without them, everything works
from selenium import webdriver
import unittest
from selenium.webdriver.common.keys import Keys
import time
def setup(self):
browser = webdriver.Chrome("C:\\Users\\Eugene\\Documents\\Python\\Tests\\Inst\\chromedriver.exe")
browser.get('https://www.google.com')
def test_01(self):
input_field = browser.find_element_by_name('q') #находит строку поиска
input_field.send_keys('python') #пишем python
input_field.send_keys(Keys.ENTER) #Из импортированных Keys в 3 строке, клавиша ENTER
Answer the question
In order to leave comments, you need to log in
The self argument is necessary for functions that are inside the class (methods), they pass a class or an instance of a class. This is necessary for accessing native attributes and methods.
In your case, there is no need for them, since the functions are outside the class.
But if you want to assign them to any class methods, then this self argument will be necessary.
The author of the video is incompetent. It is likely that he is also a newcomer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question