-2

The problem is although i can see the method I'm calling, the error says I don't have a method the way I call. Here is the error:

Traceback (most recent call last):
  File "C:\Users\htuna\selenium-playground\src\query\ncts_query.py", line 21, in <module>
    query.query_press_key()
  File "C:\Users\htuna\selenium-playground\src\query\ncts_query.py", line 13, in query_press_key
    self.__chrome.press_key("/html/body/form/div[4]/div[2]/div[1]/div/div[3]/div/div/div[2]/table[1]/tbody/tr/td/table/tbody/tr[4]/td[2]/input",
    ^^^^^^^^^^^^^
AttributeError: 'Query' object has no attribute '_Query__chrome'

I can use method from Chrome() classes in Ncts() classes however I can't use the same method under Query() class. Here is my code:

from src.query.ncts_query_data import QueryData
from src.login.ncts_login import Ncts
from src.browser.chrome import Chrome

class Query:

    def _init_(self, queryData: QueryData, ncts: Ncts, chrome: Chrome):
        self.__queryData = queryData
        self.__ncts = ncts
        self.__chrome = chrome

    def query_press_key(self):
        self.__chrome.press_key("/html/body/form/div[4]/div[2]/div[1]/div/div[3]/div/div/div[2]/table[1]/tbody/tr/td/table/tbody/tr[4]/td[2]/input",
                                "DENEME")

query = Query()
ncts = Ncts()

ncts.login()
ncts.open_guarentee_query()
query.query_press_key()

1 Answer 1

0

There are 2 issues with your class definition.

  1. It should be __init__ not _init_. (Double underscore)
  2. You cannot access directly __chrome since you wrote it with double underscore (__). It means that it should not be accessed outside of class. It is similar to a private variable but not as private with other languages.

To fix your code here is a sample.

from src.query.ncts_query_data import QueryData
from src.login.ncts_login import Ncts
from src.browser.chrome import Chrome

class Query:

    def __init__(self, queryData: QueryData, ncts: Ncts, chrome: Chrome):
        self.__queryData = queryData
        self.__ncts = ncts
        self.chrome = chrome

    def query_press_key(self):
        self.chrome.press_key("/html/body/form/div[4]/div[2]/div[1]/div/div[3]/div/div/div[2]/table[1]/tbody/tr/td/table/tbody/tr[4]/td[2]/input",
                                "DENEME")
Sign up to request clarification or add additional context in comments.

2 Comments

I changed __init__ and chrome owever it doesn't work properly. It was opening 3 Chrome browsers. I also changed my code that way: query = Query(queryData=QueryData, ncts=Ncts, chrome=Chrome) ncts = Ncts() ncts.login() ncts.open_guarentee_query() query.query_press_key() now it opens 1 Chrome browser but error says: TypeError: Chrome.press_key() missing 1 required positional argument: 'self'
Your first issue was AttributeError: 'Query' object has no attribute '_Query__chrome', the changes fixed the issue since you are not encountering it anymore. The issue you encountered is another issue. I would suggest you to read more about how python class works.

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.