def try_dec(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except TimeoutException as ex:
error_log = "Error in function: {0} with args:{1} \n{2}"
print(error_log.format(func.__name__, args[1], ex))
return -1
return wrapper
class Browser:
def __init__(self, delay=2):
patch = os.getcwd() + "\\" + "chromedriver.exe"
self.driver = webdriver.Chrome(patch)
self.set_delay(delay)
def load_page(self, address):
self.driver.get(address)
def set_delay(self, delay=2):
self.wait = WebDriverWait(self.driver, delay)
def wait_xpath(self, xpath):
element = self.wait.until(ec.element_to_be_clickable((By.XPATH, xpath)))
return element
@try_dec
def click(self, btn):
button = self.wait_xpath(btn)
button.click()
def shutdown(self):
self.driver.close()