0

I've continually looked up solutions to this and I can't find a simple answer. I'm trying to create an object from an imported class, and then call a method on that object.

from MySchedule import *
my_schedule = MySchedule(self.driver)
my_schedule.navigate_to_my_schedule() # getting an error here

Error is

AttributeError: MySchedule object has no attribute 'navigate_to_my_schedule'

Code from MySchedule.py:

class MySchedule:

    def __init__(self, driver):
        self.driver = driver
        self.nav_btn = self.driver.find_element_by_id('locButton_1')
        self.header = self.driver.find_element_by_id('panelTitle_1')

    def navigate_to_my_schedule(self):
        self.nav_btn.click()
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
logeyg
  • 549
  • 2
  • 8
  • 31

1 Answers1

2

The problem is that you're using MySchedule as both the module name and the class name, and are using from MySchedule import *.

I'd recommend changing the import statement to

import MySchedule

and referring to the class as MySchedule.MySchedule.

For further discussion of wildcard imports, see Should wildcard import be avoided?

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • thanks. how could I avoid using something like MySchedule.MySchedule and just use MySchedule? – logeyg Aug 07 '14 at 19:30
  • @logan_gabriel: Rename the module to `my_schedule` and import the class like so: `from my_schedule import MySchedule`. – NPE Aug 07 '14 at 19:49