Best Python code snippet using lettuce_webdriver_python
update.py
Source:update.py
...149 if not self.is_logined:150 display_comment_selector = (151 '.userContentWrapper [data-testid="UFI2CommentsCount/root"]'152 )153 fb.click_by_selector(driver=self.browser, selector=display_comment_selector)154 time.sleep(random.uniform(2, 3))155 def turn_off_comment_filter(self):156 filter_menu_link_selector = '[data-testid="UFI2ViewOptionsSelector/root"] [data-testid="UFI2ViewOptionsSelector/link"]'157 filter_menu_selector = '[data-testid="UFI2ViewOptionsSelector/menuRoot"]'158 unfiltered_option_selector = '[data-testid="UFI2ViewOptionsSelector/menuRoot"] [data-ordering="RANKED_UNFILTERED"]'159 fb.click_by_selector(driver=self.browser, selector=filter_menu_link_selector)160 logger.debug(161 f'crawler: clicked comment filter button with selector="{filter_menu_link_selector}" \n'162 )163 fb.move_to_element_by_selector(164 driver=self.browser, selector=filter_menu_selector165 )166 logger.debug(167 f'crawler: comment filter menu is shown with selector="{filter_menu_selector}" \n'168 )169 fb.click_by_selector(driver=self.browser, selector=unfiltered_option_selector)170 logger.debug(171 f'crawler: clicked comment filter "RANKED_UNFILTERED" with selector="{unfiltered_option_selector}" \n'172 )173 def load_comment(self, depth):174 comment_expander_selector = '[data-testid="UFI2CommentsPagerRenderer/pager_depth_{}"]'.format(175 depth176 )177 clicked_count = 0178 empty_count = 0179 comment_loaders_total = 0180 self.log_crawler(depth, comment_loaders_total, clicked_count, empty_count)181 while (int(time.time()) - self.start_at) < self.limit_sec:182 comment_loaders = self.post_node.find_elements_by_css_selector(183 comment_expander_selector184 )185 comment_loaders_total = len(comment_loaders)186 is_clicked = False187 if comment_loaders_total > 0:188 try:189 is_clicked = fb.click_by_selector(190 driver=self.browser, selector=comment_expander_selector191 )192 except MoveTargetOutOfBoundsException as e:193 # https://www.facebook.com/photo.php?fbid=3321929767823884&set=p.3321929767823884&type=3&theater194 dialog_close_button = self.browser.find_element_by_link_text("éé")195 dialog_close_button and dialog_close_button.click()196 if not is_clicked:197 empty_count += 1198 else:199 clicked_count += 1200 self.log_crawler(depth, comment_loaders_total, clicked_count, empty_count)201 time.sleep(random.uniform(2, 3))202 crawled_time = int(time.time()) - self.start_at203 time_status = f"[update.py - load_comment] LimitSec: {self.limit_sec}, Crawled: {crawled_time}. is_over_limit_sec={self.limit_sec < crawled_time}"...
css_selector_steps.py
Source:css_selector_steps.py
...76 elem = find_element_by_jquery(step, world.browser, selector)77 if not elem.is_selected():78 elem.click()79@step(r'I click \$\("(.*?)"\)$')80def click_by_selector(step, selector):81 # No need for separate button press step with selector style.82 elem = find_element_by_jquery(step, world.browser, selector)83 elem.click()84@step(r'I follow the link \$\("(.*?)"\)$')85def click_by_selector(step, selector):86 elem = find_element_by_jquery(step, world.browser, selector)87 href = elem.get_attribute('href')88 world.browser.get(href)89@step(r'\$\("(.*?)"\) should be selected$')90def click_by_selector(step, selector):91 # No need for separate button press step with selector style.92 elem = find_element_by_jquery(step, world.browser, selector)93 assert_true(step, elem.is_selected())94@step(r'I select \$\("(.*?)"\)$')95def select_by_selector(step, selector):96 option = find_element_by_jquery(step, world.browser, selector)97 selectors = find_parents_by_jquery(world.browser, selector)98 assert_true(step, len(selectors) > 0)99 selector = selectors[0]100 selector.click()101 sleep(0.3)102 option.click()103 assert_true(step, option.is_selected())104@step(r'There should not be an element matching \$\("(.*?)"\)$')...
get_data.py
Source:get_data.py
...15 el_input.click()16 el_input.send_keys(text)17 el_input.send_keys(Keys.ENTER)18 time.sleep(3)19def click_by_selector(driver, dropdown: str, element: str) -> None:20 driver.find_element_by_xpath(dropdown).click()21 driver.find_element_by_xpath(element).click()22 time.sleep(3)23# show english site24os.environ["LANG"] = "en_US.UTF-8"25# get browser26fireFoxOptions = webdriver.FirefoxOptions()27fireFoxOptions.headless = True28driver = webdriver.Firefox(options=fireFoxOptions)29driver.get("https://survstat.rki.de/Content/Query/Create.aspx")30# reset to standard filter31driver.find_element_by_id(32 "ContentPlaceHolderMain_ContentPlaceHolderAltGridFull_ButtonStandardFilter").click()33time.sleep(5)34# enter COVID35enter_by_selector(driver,36 "#ContentPlaceHolderMain_ContentPlaceHolderAltGridFull_RepeaterFilter_RepeaterFilterLevel_1_ListBoxFilterLevelMembers_0_chosen > ul:nth-child(1) > li:nth-child(1) > input:nth-child(1)",37 "COVID-19")38# enter city39county = "City of Kiel"40# county = "Görlitz County"41enter_by_selector(driver,42 "#ContentPlaceHolderMain_ContentPlaceHolderAltGridFull_RepeaterFilter_RepeaterFilterLevel_3_ListBoxFilterLevelMembers_2_chosen > ul:nth-child(1) > li:nth-child(1) > input:nth-child(1)",43 county)44# scroll down45driver.execute_script("window.scrollBy(0,500)")46# age stratification in 5 year intervals47click_by_selector(driver,48 "/html/body/form[1]/div[3]/div[1]/div[2]/div/div[2]/div/div/div[3]/div[1]/div/a/span",49 "/html/body/form[1]/div[3]/div[1]/div[2]/div/div[2]/div/div/div[3]/div[1]/div/div/ul/li[18]")50time.sleep(3)51# season starting with week 2752click_by_selector(driver,53 "/html/body/form[1]/div[3]/div[1]/div[2]/div/div[2]/div/div/div[3]/div[3]/div/a/span",54 "/html/body/form[1]/div[3]/div[1]/div[2]/div/div[2]/div/div/div[3]/div[3]/div/div/ul/li[7]")55time.sleep(3)56# scroll down57driver.execute_script("window.scrollBy(0,500)")58# incidence59driver.find_element_by_id(60 "ContentPlaceHolderMain_ContentPlaceHolderAltGridFull_CheckBoxIncidence").click()61time.sleep(3)62# get data63table = driver.find_element_by_id(64 "ContentPlaceHolderMain_ContentPlaceHolderAltGridFull_GridViewResult").text65results = {}66lines = table.split('\n')...
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!!