Best Python code snippet using SeleniumBase
LoginTest.py
Source:LoginTest.py
...89 self.home.getSearchProductsTextBox().send_keys(self.testdata['search']['item3'])90 self.home.getSearchIcon().click()91 sel = Select(self.home.getPriceSelect())92 sel.select_by_value('20000')93 timeouthandlers.wait_for_element_clickable(self.driver,self.home.get6GBRamCheckBox())94 time.sleep(5)95 self.home.get6GBRamCheckBox().click()96 timeouthandlers.wait_for_element_clickable(self.driver,self.home.getSamsungCheckbox())97 time.sleep(5)98 self.home.getSamsungCheckbox().click()99 timeouthandlers.wait_for_element_clickable(self.driver,self.home.getOSOption())100 time.sleep(5)101 self.home.getOSOption().click()102 timeouthandlers.wait_for_element_clickable(self.driver,self.home.getAndroidOSCheckbox())103 time.sleep(5)104 self.home.getAndroidOSCheckbox().click()105 time.sleep(5)106 filteredItems = self.home.getfilteredItems()107 for item in filteredItems:108 time.sleep(2)109 print(item.text)110 if item.text.__contains__(self.testdata['subsearch']['subitem2']):111 item.click()112 break113 windows = self.driver.window_handles114 parendtid = windows[0]115 childid = windows[1]116 self.driver.switch_to_window(childid)117 timeouthandlers.wait_for_element_clickable(self.driver,self.home.getAddToCart())118 time.sleep(5)119 self.home.getAddToCart().click()120 time.sleep(5)121 self.driver.close()122 self.driver.switch_to_window(parendtid)123 self.driver.refresh()124 timeouthandlers.wait_for_element_clickable(self.driver,self.home.getCartIcon())125 self.home.getCartIcon().click()126 time.sleep(5)127 timeouthandlers.wait_for_element_clickable(self.driver,self.cart.getRemoveLink())128 self.cart.getRemoveLink().click()129 timeouthandlers.wait_for_element_clickable(self.driver,self.cart.getRemoveBtn())130 self.cart.getRemoveBtn().click()131 timeouthandlers.wait_for_element_visibility(self.driver,self.cart.getItemRemoveSuccessMsg())132 assert self.cart.getItemRemoveSuccessMsg().is_displayed()133 time.sleep(5)134 def testHandlingFrame(self):135 self.driver.get("https://timesofindia.indiatimes.com/")136 time.sleep(5)137 self.driver.switch_to_frame('cardembed-data-tickertable-5-1-335-853-')138 self.driver.find_element_by_xpath("//div[text()='Cryptocurrency']").click()139 time.sleep(5)140 def testGetCSSValues(self):141 time.sleep(5)142 print('Color :',self.login.getLoginBtn().value_of_css_property(self.testdata['css']['color']))143 print('Font-Family :',self.login.getLoginBtn().value_of_css_property(self.testdata['css']['fontfamily']))...
accounts_page.py
Source:accounts_page.py
...13 super(AccountsPage, self).__init__(wd, url)14 def fill_account_tile(self, importer_name, import_content):15 # scroll to bottom of the page to get all the importers on16 self.wd.execute_script("window.scrollTo(0, document.body.scrollHeight);")17 self.wait_for_element_clickable(*(By.ID, importer_name + "-account-tile"))18 self.wd.find_element_by_id(importer_name + "-account-tile").click()19 self.wait_for_element_clickable(*(By.ID, importer_name + "-account-username-input"))20 self.wd.find_element_by_id(importer_name + "-account-username-input").click()21 self.wd.find_element_by_id(importer_name + "-account-username-input").send_keys(import_content)22 self.wait_for_element_clickable(*(By.ID, importer_name + "-account-username-submit"))23 self.wd.find_element_by_id(importer_name + "-account-username-submit").click()24 def is_account_connected(self, importer_name):25 self.wait_for_element_visible(*(By.ID, importer_name + "-account-toggle"))26 found = True27 # maybe needs extra sleep28 import time29 time.sleep(1)30 31 try:32 timeout = self.timeout33 self.timeout = 234 self.wait_for_element_visible(*(By.ID, importer_name + "-account-toggle-on"))35 except Exception:36 found = False37 self.timeout = timeout 38 return found39 def start_connected_accounts(self):40 self.wait_for_element_clickable(*(By.PARTIAL_LINK_TEXT, "Import my"))41 self.wd.find_element_by_partial_link_text("Import my").click()42 def finish_connected_accounts(self):43 # maybe needs extra sleep44 import time45 time.sleep(1)46 47 self.wait_for_element_clickable(*(By.PARTIAL_LINK_TEXT, "back to profile"))48 self.wd.find_element_by_partial_link_text("back to profile").click()49 def wait_till_import_done(self):...
seleniumwaitclickable.py
Source:seleniumwaitclickable.py
...5from selenium.common.exceptions import TimeoutException6from datetime import datetime7driver = webdriver.Firefox(executable_path="geckodriver.exe")8driver.get("https://slackingslacker.github.io/seleniumindex#/seleniumwait")9def wait_for_element_clickable(wait_time: int, id: str):10 try:11 print("[{}] Waiting clickable".format(str(datetime.now())))12 WebDriverWait(driver, wait_time).until(13 EC.element_to_be_clickable((By.ID, id))14 )15 print("[{}] Element clickable".format(str(datetime.now())))16 except TimeoutException as e:17 print("[{}] Element not clickable".format(str(datetime.now())))18wait_for_element_clickable(3, "clickableBtn")19wait_for_element_clickable(6, "unclickableBtn")...
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!!