2

I am using Selenium WebDriver in Python in Pycharm, where I am using a class having 2 test functions.

class goodsweb(unittest.TestCase):

    def setUp(self):
        driverlocation ="/Users/new/Documents/Learning/Drivers/selenium-2.53.1/py/selenium/webdriver/chromedriver"
        os.environ["webdriver.chrome.driver"] = driverlocation
        self.driver = webdriver.Chrome(driverlocation)

    def test_Test1(self):
        self.EmailEntry = input("Please Enter Email Address: ")
        self.EmailAddress.send_keys(self.EmailEntry)
        self.Password.clear()
        self.password='12345678'
        self.Password.send_keys(self.password)

    def test_Test2(self):
        self.LoginEmail = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[1]/input[@type='email']")
        self.LoginEmail.clear()
        self.LoginEmail.click()
        self.LoginEmail.send_keys(self.EmailEntry)

        self.LoginPassword = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[1]/input[@type='password']")
        self.LoginPassword.clear()
        self.LoginPassword.click()
        self.LoginPassword.send_keys(self.password)

Now What I want is get access of EmailEntry and Password of test_Test1 in test_Test2

Whenever I am running the code, I am having this error:

AttributeError: 'goodsweb' object has no attribute 'EmailEntry'

6
  • always put full error message (Traceback). There are other useful informations Commented Dec 8, 2017 at 8:14
  • where is your EmailEntry field ? It can't accessible in goodsweb class. Declare in this class or define as static. Commented Dec 8, 2017 at 8:31
  • @furas It was very a long code, so I have just entered main things which were required for this problem. Commented Dec 8, 2017 at 8:57
  • @Hiten I have defined it as static, and it worked. but my question is, is that good practice? Commented Dec 8, 2017 at 8:58
  • I have got another question, How Can I call any fucntion, means that only specific function on other script. Means If there are 2 fucntions i.e. Function1 and Function2 in ClassA of ScriptA, I want to access only and only Function2 in ScriptB. Commented Dec 8, 2017 at 8:59

1 Answer 1

1

where is your EmailEntry field ?

It can't accessible in goodsweb class. Declare in this class or define as static so you can use in any other classes.

If you want to use one field in other classes or function then you have to define field as static.

For functions the concept is same. You can defined function as static like

public static void main(){
     // your logic
}

For python ::

class MyClass(object):
    def the_static_method(x):
        print x
    the_static_method = staticmethod(the_static_method)

MyClass.the_static_method(2) # outputs 2
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for suggestion and its Python..not Java.

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.