E
E
Eugene2020-02-08 16:00:16
Python
Eugene, 2020-02-08 16:00:16

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

3 answer(s)
S
SvinkaBacilka, 2020-02-21
@evgentor

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.

S
Sergey Gornostaev, 2020-02-08
@sergey-gornostaev

The author of the video is incompetent. It is likely that he is also a newcomer.

D
Dimonchik, 2020-02-08
@dimonchik2013

- why do you draw a dash and constantly cross it out?
- this is X..... !!!!!! ????????????

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question