How to use reset_driver method in Selene

Best Python code snippet using selene_python

action.py

Source:action.py Github

copy

Full Screen

...29 '116.110.18.247:1080',30 '113.176.195.145:4153'31 ]32 pass33 def reset_driver(self):34 # t = random.choice(self.proxyList)35 # self.proxyList.remove(t)36 # print(t, self.proxyList)37 # chromeOptions = webdriver.ChromeOptions()38 # chromeOptions.add_argument('--proxy-server={}'.format(t))39 self.driver = webdriver.Chrome(executable_path=self.path)40 # self.driver = webdriver.ChromiumEdge(executable_path=self.path)41 self.driver.get("https://www.onlineocr.net")42 43 def push_something_by_id(self, something, path):44 try:45 element = WebDriverWait(self.driver, 20).until(46 EC.presence_of_element_located((By.ID, something))47 )48 element.send_keys(path)49 except:50 self.driver.close()51 self.reset_driver()52 def click_something_by_id(self, something):53 try:54 element = WebDriverWait(self.driver, 30).until(55 EC.presence_of_element_located((By.ID, something))56 )57 # print(element)58 self.driver.execute_script("arguments[0].click();", element)59 except:60 self.driver.close()61 self.reset_driver()62 63 def click_something_by_xpath(self, something):64 try:65 element = WebDriverWait(self.driver, 30).until(66 EC.presence_of_element_located((By.XPATH, something))67 )68 # print(element)69 self.driver.execute_script("arguments[0].click();", element)70 except:71 self.driver.close()72 self.reset_driver()73 def select(self):74 select = Select(self.driver.find_element_by_name(75 'ctl00$MainContent$comboOutput'))76 select.select_by_value("Microsoft Excel (xlsx)")77 def get(self,path_image):78 if self.amount%10 == 0:79 self.reset_driver()80 self.push_something_by_id("fileupload", path_image)81 time.sleep(5)82 self.select()83 self.click_something_by_id("MainContent_btnOCRConvert")84 time.sleep(10)85 self.click_something_by_xpath('//*[@id="MainContent_lnkBtnDownloadOutput"]')86 # print("xuli!!!done")87 # print(self.amount)...

Full Screen

Full Screen

google.py

Source:google.py Github

copy

Full Screen

...5import time6class Google_Crawler:7 def __init__(self, implicitly_wait_time=10):8 self.implicitly_wait_time = implicitly_wait_time9 self.reset_driver()10 def reset_driver(self):11 print("reset driver!")12 chrome_driver_path = os.path.join(os.getcwd(), "chromedriver")13 chrome_options = webdriver.ChromeOptions()14 chrome_options.add_argument("--headless")15 chrome_options.add_argument("--no-sandbox")16 chrome_options.add_argument("--disable-dev-shm-usage")17 self.driver = webdriver.Chrome(chrome_driver_path, options=chrome_options)18 self.driver.implicitly_wait(self.implicitly_wait_time)19 def get_page_soup(self, url):20 self.driver.get(url)21 page_html = self.driver.page_source22 page_soup = BeautifulSoup(page_html, "html.parser")23 return page_soup24 def search(self, word):25 url = f"https://www.google.com/search?q={quote_plus(word)}"26 page_soup = self.get_page_soup(url)27 result = []28 g_tags = page_soup.select(".g")29 if g_tags == None or len(g_tags) == 0:30 self.driver.quit()31 time.sleep(2)32 self.reset_driver()33 time.sleep(2)34 for g in g_tags:35 if g.find("div", attrs={"class": "LC20lb"}):36 result.append(g.select_one(".LC20lb").text.strip()) # 타이틀37 if g.find("div", attrs={"class": "VwiC3b"}):38 result.append(g.select_one(".VwiC3b").text.strip()) # 내용39 return result40 def search_highlighted(self, word):41 url = f"https://www.google.com/search?q={quote_plus(word)}"42 page_soup = self.get_page_soup(url)43 modifier = page_soup.select_one("a.gL9Hy")44 if modifier:45 word = modifier.text46 url = f"https://www.google.com/search?q={quote_plus(word)}"47 page_soup = self.get_page_soup(url)48 data = page_soup.find_all("em")49 if not data:50 self.driver.quit()51 sleep(3)52 self.reset_driver()53 return self.search_highlighted(word, True)54 result = []55 for element in data:56 result.extend(element.text.split())...

Full Screen

Full Screen

naver.py

Source:naver.py Github

copy

Full Screen

...5import time6class Naver_Crawler:7 def __init__(self, implicitly_wait_time=10):8 self.implicitly_wait_time = implicitly_wait_time9 self.reset_driver()10 def reset_driver(self):11 print("reset driver!")12 chrome_driver_path = os.path.join(os.getcwd(), "chromedriver")13 chrome_options = webdriver.ChromeOptions()14 chrome_options.add_argument("--headless")15 chrome_options.add_argument("--no-sandbox")16 chrome_options.add_argument("--disable-dev-shm-usage")17 self.driver = webdriver.Chrome(chrome_driver_path, options=chrome_options)18 self.driver.implicitly_wait(self.implicitly_wait_time)19 def search(self, word):20 url = f"https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query={quote_plus(word)}"21 self.driver.get(url)22 page_html = self.driver.page_source23 page_soup = BeautifulSoup(page_html, "html.parser")24 result = []25 total_tit = page_soup.select(".total_tit")26 if total_tit == None or len(total_tit) == 0:27 self.driver.quit()28 time.sleep(2)29 self.reset_driver()30 time.sleep(2)31 api_txt_lines = page_soup.select(".api_txt_lines")32 if api_txt_lines == None or len(api_txt_lines) == 0:33 self.driver.quit()34 time.sleep(2)35 self.reset_driver()36 time.sleep(2)37 for total_tit in total_tit:38 result.append(total_tit.text.strip())39 for api_txt_lines in page_soup.select(".api_txt_lines"):40 result.append(api_txt_lines.text.strip())...

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 Selene 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