How to use web_element method in toolium

Best Python code snippet using toolium_python

webdriver_functions.py

Source:webdriver_functions.py Github

copy

Full Screen

...6 def __init__(self):7 super(WebdriverFunctions, self).__init__()8 self.text_value = ''9 self.xpath_send_keys = ''10 def web_element(self, by_locator, element):11 result = False12 attempts = 013 while attempts < 10:14 try:15 xpath_text = self.driver.find_element(by_locator, element)16 self.text_value = xpath_text.text17 result = True18 break19 except Exception as error:20 ui_logger.error(error)21 time.sleep(2)22 attempts += 123 # print('Number of attempts = {}'.format(attempts))24 return result...

Full Screen

Full Screen

base_element.py

Source:base_element.py Github

copy

Full Screen

1from selenium.webdriver.support.wait import WebDriverWait2from selenium.webdriver.support import expected_conditions as EC3from selenium.webdriver.support.select import Select4from selenium.common.exceptions import TimeoutException5class BaseElement(object):6 def __init__(self, driver, locator):7 self.driver = driver8 self.locator = locator9 self.web_element = None10 self.find_element()11 def find_element(self):12 element = WebDriverWait(self.driver, 10).until(13 EC.visibility_of_element_located(locator=self.locator)14 )15 self.web_element = element16 return None17 def click(self):18 element = WebDriverWait(self.driver, 10).until(19 EC.element_to_be_clickable(locator=self.locator)20 )21 element.click()22 return None23 def enter_text(self, text):24 self.web_element.send_keys(text)25 return None26 def clear(self):27 self.web_element.clear()28 return None29 def attribute(self, attribute_name):30 attribute = self.web_element.get_attribute(attribute_name)31 return attribute32 @property33 def text(self):34 text = self.web_element.text35 return text36 @property37 def dropdown_options(self):38 selected_element = Select(self.web_element)39 list_of_options = [element.text for element in selected_element.options]40 return list_of_options41 @property42 def get_text(self):43 text = self.web_element.get_attribute('value')44 return text45 def select_option_by_value(self, value):46 selected_element = Select(self.web_element)47 selected_element.select_by_value(value)48 return None49 @property50 def currently_selected_option_text(self):51 selected_element = Select(self.web_element)52 text = selected_element.first_selected_option.text53 return text54 def is_clickable(self):55 wait = WebDriverWait(self.driver, 10)56 try:57 wait.until(EC.element_to_be_clickable())58 element_state = True59 except TimeoutException:60 element_state = False61 return element_state62 def is_selected(self):63 state = self.web_element.get_attribute("checked")...

Full Screen

Full Screen

inspect.py

Source:inspect.py Github

copy

Full Screen

1"""Helper functions inspecting if given web element fulfil some criterion2"""3__author__ = "Bartosz Walkowicz"4__copyright__ = "Copyright (C) 2016 ACK CYFRONET AGH"5__license__ = "This software is released under the MIT license cited in " \6 "LICENSE.txt"7import re8from selenium.common.exceptions import TimeoutException9from tests.gui.conftest import WAIT_FRONTEND10from selenium.webdriver.support import expected_conditions as EC11from selenium.webdriver.support.wait import WebDriverWait as Wait12def is_active(browser, web_element):13 """Check if given web element is the active one in given browser.14 """15 try:16 Wait(browser, WAIT_FRONTEND).until(17 lambda s: web_element == s.switch_to.active_element18 )19 except TimeoutException:20 return False21 else:22 return True23def is_visible(browser, web_element):24 """Check if given web element is visible in given browser.25 """26 try:27 Wait(browser, WAIT_FRONTEND).until(EC.visibility_of(web_element))28 except TimeoutException:29 return False30 else:31 return True32def is_enabled(web_element):33 """Check if given web element is enabled in given browser.34 """35 return web_element.is_enabled()36def contains_text_of_given_pattern(web_element, pattern):37 """Check if given web element contains given pattern.38 """39 return re.match(pattern, web_element.text)40def selector(browser, text='', ignore_case=False, check_visibility=False,41 check_if_enabled=False, check_if_active=False):42 """Chain criterion checking and return function that will conduct check.43 """44 conditions = []45 if text:46 text_regexp = re.compile(text, re.I if ignore_case else 0)47 conditions.append(lambda item:48 contains_text_of_given_pattern(item, text_regexp)49 )50 if check_visibility:51 conditions.append(lambda item: is_visible(browser, item))52 if check_if_enabled:53 conditions.append(is_enabled)54 if check_if_active:55 conditions.append(lambda item: is_active(browser, item))56 def _select(item):57 return all(condition(item) for condition in conditions)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful