selenium - Issue with global variables in python -


i getting issue global variable declared in python file. not have class declaration in file. declaring variables in class none type. , modifying variables in function.

when calling variables inside class importing them, instead of modified value returning none type only.

below code

from selenium import webdriver pages.pagemethods.google_methods import methods   browser = none s = none   def before_feature(context, feature):     print("before feature")  def before_scenario(context, scenario):     print('before scenario', scenario.name)     context.driver = webdriver.firefox()     #context.driver.maximize_window()     browser = context.driver     global s     s = methods(browser)     s.samplemethod()  def after_scenario(context, scenario):     print("after scenario", scenario.name)     context.driver.quit()  def after_feature(context, feature):     print("after feature") 

->here calling 's' variable inside class,it returning none type instead of object assigned class

please help

here code calling variable

from features.environment import *   use_step_matcher("re")  fileconfig('logging.ini') log = logging.getlogger('slogger')   @given("i on google page '(.*)'") def navigate(context, url1):     context.url = url1     log.info("this log statement")     context.driver.get(url1)     context.driver.implicitly_wait(10)   @then("i enter value search box '(.*)'") def step_impl(context, text):     print("selector:=>", google.search_box)     context.driver.find_element(*google.search_box).send_keys(text)     print("url in second step is:=>", context.url)     time.sleep(1)     s.printtitle() 

and getting error:

attributeerror: 'nonetype' object has no attribute 'printtitle'

you need use global operator

example:

global_var = list()  def somefunc():     global global_var      global_var.append(1)  somefunc() print global_var 

out: [1]


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -