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:
In today’s fast-paced world, the primary goal of every business is to release their application or websites to the end users as early as possible. As a result, businesses constantly search for ways to test, measure, and improve their products. With the increase in competition, faster time to market (TTM) has become vital for any business to survive in today’s market. However, one of the possible challenges many business teams face is the release cycle time, which usually gets extended for several reasons.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.
In an ideal world, you can test your web application in the same test environment and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.
Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.
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!!