Liel00
Liel00

Reputation: 49

object has no attribute 'driver'


Hello I am trying to build an automation infrastructure I built an ObjectRepository where commands are implemented in selenium where I use ObjectTest and pass the function to TestOne.
The error is:

TestOne :: test_one - AttributeError: 'ObjectTest' object has no attribute 'driver'

class ObjectRepository:

    def __init__(self, driver):
        self.driver = driver

    def click1(self, element):
        return self.driver.find_element_by_xpath(element).click()
class ObjectTest:

    search = (By.XPATH, "//a[contains(text(),'Gmail')]")

    def click_gmail(self):
        a = ObjectRepository(self.driver)
        a.click1(*ObjectTest.search)
class TestOne(Base.Base):

    def test_one(self):
        one = ObjectTest()
        one.click_gmail()

Upvotes: 0

Views: 3846

Answers (2)

Fasinu Dennis
Fasinu Dennis

Reputation: 11

Change your code to this:

def __init__(self, driver=None):
    if driver is None:
        driver={}
    else:
        self.driver= driver

Upvotes: 1

Prophet
Prophet

Reputation: 33361

From the code in the question I can't see that

  1. driver defined and initialized in class ObjectRepository is passed into class ObjectTest.
  2. there is an import such as
from selenium import webdriver

in class ObjectRepository so as Python will "understand" what self.driver = driver means

Upvotes: 1

Related Questions