Best Python code snippet using SeleniumBase
base_page.py
Source:base_page.py
...15 return self.browser.find_element(how, what)16 def get_element_if_clickable(self, how, what):17 assert self.is_element_present(how, what, timeout=3),\18 f'Cannot get element "{str(how)}.{str(what)}"'19 assert self.is_element_clickable(how, what, timeout=3),\20 f'Element "{str(how)}.{str(what)}" is not clickable'21 return self.browser.find_element(how, what)22 def is_element_present(self, how, what, timeout=4):23 try:24 WebDriverWait(self.browser, timeout).until(EC.presence_of_element_located((how, what)))25 except TimeoutException:26 return False27 return True28 def get_all_elements(self, how, what):29 assert self.are_elements_present(how, what),\30 f'Cannot get elementS "{str(how)}.{str(what)}"'31 return self.browser.find_elements(how, what)32 def are_elements_present(self, how, what, timeout=5):33 try:34 WebDriverWait(self.browser, timeout).until(EC.presence_of_all_elements_located((how, what)))35 except TimeoutException:36 return False37 return True38 def is_not_element_present(self, how, what, timeout=4):39 try:40 WebDriverWait(self.browser, timeout).until(EC.presence_of_element_located((how, what)))41 except TimeoutException:42 return True43 return False44 def is_element_clickable(self, how, what, timeout=5):45 try:46 WebDriverWait(self.browser, timeout).until(EC.element_to_be_clickable((how, what)))47 except TimeoutException:48 return False49 return True50 def is_appeared(self, how, what, timeout=10):51 try:52 WebDriverWait(self.browser, timeout, 1, TimeoutException).until(EC.presence_of_element_located((how, what)))53 except TimeoutException:54 return False55 return True56 def is_disappeared(self, how, what, timeout=4):57 try:58 WebDriverWait(self.browser, timeout, 1, TimeoutException).until_not(EC.presence_of_element_located((how, what)))...
yandex_images_page.py
Source:yandex_images_page.py
...24 text = inp.get_attribute("value")25 return text26 @allure.step('ÐÑкÑÑÑие пеÑвой каÑÑинки')27 def open_first_image(self):28 self.is_element_clickable(*YandexImagesPageLocators.FIRST_IMAGE)29 @allure.step('ÐÑовеÑка Ñого, ÑÑо каÑÑинка полноÑÑÑÑ Ð¾ÑкÑÑÑа')30 def check_image_is_fully_open(self):31 assert self.is_element_present(*YandexImagesPageLocators.IMAGE_FULLSCREEN)32 @allure.step('ÐзÑÑие ÑÑÑлки на каÑÑинкÑ')33 def get_image_source(self):34 img = self.browser.find_element(*YandexImagesPageLocators.FOR_SOURCE_OF_IMAGE)35 source = img.get_attribute('src')36 return source37 @allure.step('ÐажаÑие на ÐºÐ½Ð¾Ð¿ÐºÑ ÑледÑÑÑей каÑÑинки')38 def next_image_btn_click(self):39 self.is_element_clickable(*YandexImagesPageLocators.NEXT_IMAGE_BTN)40 @allure.step('ÐажаÑие на ÐºÐ½Ð¾Ð¿ÐºÑ Ð¿ÑедÑдÑÑей каÑÑинки')41 def prev_image_btn_click(self):...
admin_login_page.py
Source:admin_login_page.py
...8 "login_submit_btn": (By.CSS_SELECTOR, "div.text-right > button"),9 "forgotten_password_btn": (By.CSS_SELECTOR, "div.form-group > span > a")10 }11 def login_with(self, credentials: tuple, wait=5):12 self.is_element_clickable(self.elements['name_input'], wait).send_keys(credentials[0])13 self.is_element_clickable(self.elements['password_input'], wait).send_keys(credentials[1])14 self.is_element_clickable(self.elements['login_submit_btn'], wait).click()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!