-1

In Selenium Webdriver , I am working on Python in Pycharm In which I am using simple class in which two methods are called to open URL in Chrome and Safari respectively.

from selenium import webdriver


    class Automation():
        def Safari(self):
            driver = webdriver.Safari()
            driver.get('https://bizplace.theentertainerme.com')

        def Chrome(self):
            driver = webdriver.Chrome('/usr/local/bin/chromedriver')
            driver.get('https://bizplace.theentertainerme.com')

    auto = Automation
    auto.Safari(self)

Now After Executing it, I am getting an error like this:

    auto.Safari(self)
NameError: name 'self' is not defined

I am trying to install self package via command line, its throwing me an error like this:

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/hh/bwg2n8w54cd7852cx91v21qm0000gp/T/pip-build-XVmlLB/public/setup.py", line 28, in <module>
        setup_cfg_data = read_configuration(path)
      File "/private/var/folders/hh/bwg2n8w54cd7852cx91v21qm0000gp/T/pip-build-XVmlLB/public/setup.py", line 23, in read_configuration
        val = open(val).read()
    IOError: [Errno 2] No such file or directory: './README.rst'

Can some one help me here.

Grr
  • 15,553
  • 7
  • 65
  • 85
Taimoor Pasha
  • 192
  • 2
  • 3
  • 16

1 Answers1

0

Not sure why you are trying to install the self package, you are not using it in your code, and you do not need it.

Your issue is a simple mistake here when calling your method:

auto = Automation
auto.Safari(self)

This code is outside your class, the name self is not defined here, and you get the error you are seeing:

NameError: name 'self' is not defined

The correct way to call your method would be this:

auto = Automation
auto.Safari()

Since you are calling a method of an instance, self (the instance that the actual method you called belongs to) will automatically be passed as first argument.

Do not take this the wrong way, but I think you need to work your way through the Python tutorial, as this is somewhat of a basic mistake, and with more complicated code you will run into countless issues like this one and will not enjoy working on your project.

bgse
  • 8,237
  • 2
  • 37
  • 39