0

I`m writing simple scripts for test automation using Selenium WebDriver in Python, but the issue relates to Python, not to Selenium. There two classes FindByXPATH_1(base) & FindByXPATH_2(derived). I want to call an attribute "driver" from the base class in a method of FindByXPATH_2, but when I ran the code the AttributeError shows up: "type object 'FindByXPATH_1' has no attribute 'driver'"

Here is the code:

class FindByXPATH_1():
    def __init__(self):
        self.driver_location = '/usr/local/bin/chromedriver'
        self.driver = webdriver.Chrome(self.driver_location)
        self.driver.get('https://letskodeit.teachable.com/p/practice')

from basics.xpath_1 import FindByXPATH_1
import basics #the classes are in two different python files

class FindByXpath_2(FindByXPATH_1):
    def __init__(self):
        FindByXPATH_1.__init__(self)

    def find_by_starts_with(self):
        starting_with = FindByXPATH_1.driver.find_elements(By. XPATH, 
        '//div[@class="view-school"]//h3[starts-with(@)class, "subtitle"]')
        print(len(starting_with))

test = FindByXPATH_2()
test.find_by_starts_with()

After running the code I get a message "AttributeError: type object 'FindByXPATH_1' has no attribute 'driver'" How can I call that attribute?

1 Answer 1

1

In this line here:

    starting_with = FindByXPATH_1.driver.find_elements(By. XPATH, 
    '//div[@class="view-school"]//h3[starts-with(@)class, "subtitle"]')

You should be calling self.driver.find_elements otherwise you are trying to access a class variable of FindByXPATH_1 and not the instance variable driver

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.