Best Python code snippet using SeleniumBase
loadlinkhtml.py
Source:loadlinkhtml.py
1from selenium import webdriver2import time3def getHtml(url, click_link_text = None, scroll_link_text = None, year=None, waittime = 2):4 5 '''6 Paramters:7 url - (http url): the entrance page we will get html from8 click_link_text - (string): the text of link that you want to click9 scroll_link_text - (string): the text of link that window need to scroll to view10 year - (int) Default None is year of recent updated quarter, What year's fund data do you want to get11 waittime: seconds the browser will wait after initial load and12 13 Returns:14 html - html code15 '''16 browser = webdriver.Chrome('chromedriver')17 browser.maximize_window()18 browser.get(url)19 time.sleep(waittime)20 if scroll_link_text:21 scroll_to_ele = browser.find_element_by_link_text(scroll_link_text)22 browser.execute_script("arguments[0].scrollIntoView();",scroll_to_ele)23 24 if click_link_text:25 click_button = browser.find_element_by_link_text(click_link_text)26 click_button.click()27 time.sleep(waittime)28 handles = browser.window_handles29 current_handle = browser.current_window_handle30 for handle in handles:31 if handle != current_handle:32 browser.switch_to.window(handle)33 else:34 continue35 if year: # ä»
éäºå¯¹åºé页é¢å¹´ä»½çéæ©36 year_button = browser.find_element_by_css_selector('div#pagebar label[value="'+str(year)+'"]')37 year_button.click()38 time.sleep(waittime)39 html = browser.page_source40 browser.quit()...
test_basic.py
Source:test_basic.py
...7 # self.assert_text("xkcd book", "div.results")8 # self.open("https://xkcd.com/353/")9 # self.click('a[rel="license"]')10 # self.go_back()11 # self.click_link_text("About")12 # self.click_link_text("comic #249")...
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!!