Best Python code snippet using selene_python
action.py
Source: action.py
...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)...
google.py
Source: google.py
...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())...
naver.py
Source: naver.py
...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())...
Check out the latest blogs from LambdaTest on this topic:
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.
โTest frequently and early.โ If youโve been following my testing agenda, youโre probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. Iโve encountered several teams who have a lot of automated tests but donโt use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
Hey LambdaTesters! Weโve got something special for you this week. ????
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!!