How to use wait_for_content method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

main.py

Source:main.py Github

copy

Full Screen

...71 title = el['title']72 list_of_links.append([href, title])73 for link in list_of_links:74 driver.get(link[0])75 wait_for_content()76 content = driver.page_source77 content_low = content.lower()78 counter = 079 if elem == word:80 for w in word_list:81 if content.find(w) > -1 and counter == 0:82 counter += 183 print(content.lower())84 if content_low.find("blockchain") > -1 or content_low.find("crypto ") > -1 or content_low.find("cryptocurrency") > -1 or content_low.find("crypto currency") > -1 or content.lower().find("distributed ledger") > -1:85 added = True86 payload = {87 "text": "New article found on https://www.instantmarkets.com/ with key word: " + elem + " ```" + "Title: " +88 link[1] + " \n" + "Link: "89 + link[0] + " ```"}90 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"91 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))92 else:93 continue94 else:95 if content_low.find("blockchain") > -1 or content_low.find("crypto ") > -1 or content_low.find(96 "cryptocurrency") > -1 or content_low.find("crypto currency") > -1 or content.lower().find(97 "distributed ledger") > -1:98 added = True99 payload = {100 "text": "New article found on https://www.instantmarkets.com/ with key word: " + elem + " ```" + "Title: " +101 link[1] + " \n" + "Link: "102 + link[0] + " ```"}103 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"104 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))105 # else:106 # for el in links:107 # href = "https://www.instantmarkets.com" + str(el['href'])108 # title = el['title']109 # content = driver.page_source110 # if content.lower().find("blockchain") > -1 or content.lower().find(111 # "crypto") > -1 or content.lower().find("cryptocurrency") > -1 or content.lower().find(112 # "distributed ledger") > -1:113 # payload = {114 # "text": "New article found on https://www.instantmarkets.com/ with key word: " + elem + " ```" + "Title: " +115 # title + " \n" + "Link: "116 # + href + " ```"}117 # response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"118 # "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))119def wait_for_content():120 wait_time = random.randint(2, 6)121 time.sleep(wait_time)122def get_number_of_pages(text):123 first_split = text.split('(')124 sec_split = first_split[1].split(')')125 return sec_split[0]126def previous_week_date(number):127 today = DT.date.today()128 week_ago = today - DT.timedelta(days=number)129 year = str(week_ago.year)130 month = str(week_ago.month)131 day = str(week_ago.day)132 day_name = week_ago.strftime("%A")[0:3]133 month_name = week_ago.strftime("%B")134 month_name_short = week_ago.strftime("%b")135 return year, month, day, day_name, month_name_short, month_name136def ec_europa():137 global added138 year, month, day, day_name, month_name_short, month_name = previous_week_date(7)139 try:140 for elem in keywords:141 url = f'https://ec.europa.eu/commission/presscorner/advancedsearch/en?keywords={elem}&dotyp=&parea=&pareaType=&datepickerbefore=&datebefore=&commissioner=&datepickerafter={day}%20{month_name}%20{year}&dateafter={day_name}%20{month_name_short}%20{day}%20{year}%2000:00:00%20GMT%2B0200%20(Central%20European%20Summer%20Time)&pagenumber=1'142 driver.get(url)143 wait_for_content()144 number = driver.find_element(By.CLASS_NAME, "ecl-heading.ecl-heading--h2.ecl-u-mb-m")145 try:146 num = number.find_element(By.TAG_NAME, "span").text147 pages_number = get_number_of_pages(num)148 number_of_pages = count_number_of_pages(int(pages_number))149 for i in range(number_of_pages):150 url2 = f'https://ec.europa.eu/commission/presscorner/advancedsearch/en?keywords={elem}&dotyp=&parea=&pareaType=&datepickerbefore=&datebefore=&commissioner=&datepickerafter={day}%20{month_name}%20{year}&dateafter={day_name}%20{month_name_short}%20{day}%20{year}%2000:00:00%20GMT%2B0200%20(Central%20European%20Summer%20Time)&pagenumber={i + 1}'151 driver.get(url2)152 wait_for_content()153 by_class = driver.find_elements(By.CLASS_NAME, "ecl-link.ecl-list-item__link")154 word_list, word = words_variation(elem)155 list_of_links = []156 if elem == word:157 for ele in by_class:158 href = ele.get_attribute('href')159 title = ele.find_element(By.CLASS_NAME, "ecl-list-item__title.ecl-heading.ecl-heading--h3")160 list_of_links.append([href, title.text])161 for link in list_of_links:162 driver.get(link[0])163 wait_for_content()164 content = driver.page_source165 counter = 0166 for w in word_list:167 if content.find(w) > -1 and counter == 0:168 counter += 1169 added = True170 payload = {171 "text": "New article found on https://ec.europa.eu/ with key word: " + elem + " ```" + "Title: " +172 link[1] + " \n" +173 "Link: " + link[0] + " ```"}174 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"175 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))176 else:177 continue178 else:179 for ele in by_class:180 href = ele.get_attribute('href')181 title = ele.find_element(By.CLASS_NAME, "ecl-list-item__title.ecl-heading.ecl-heading--h3")182 added = True183 payload = {184 "text": "New article found on https://ec.europa.eu/ with key word: " + elem + " ```" + "Title: " + title.text + " \n" +185 "Link: " + href + " ```"}186 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"187 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))188 except:189 continue190 except:191 return False192 driver.quit()193def last_7_days():194 list_of_days = []195 for days in range(7):196 year, month, day, day_name, month_name_short, month_name = previous_week_date(days)197 if int(day) < 10:198 day = day.replace("0", "")199 list_of_days.append([month_name_short, day, year])200 return list_of_days201def sam_gov():202 keywords2 = ['cryptocurrency']203 for elem in keywords2:204 url = f'https://sam.gov/search/?page=1&pageSize=25&sort=-modifiedDate&sfm%5Bstatus%5D%5Bis_active%5D=true&sfm' \205 f'%5BsimpleSearch%5D%5BkeywordRadio%5D=EXACT&sfm%5BsimpleSearch%5D%5BkeywordTags%5D%5B0%5D%5Bkey%5D={elem}' \206 f'&sfm%5BsimpleSearch%5D%5BkeywordTags%5D%5B0%5D%5Bvalue%5D={elem} '207 driver.get(url)208 wait_for_content()209 data_list = []210 try:211 page = driver.find_element(By.CLASS_NAME, 'sds-pagination__total').text.split(' ')212 page_number = page[1]213 count_of_ele = 0214 for number in range(int(page_number)):215 url2 = f'https://sam.gov/search/?page={number + 1}&pageSize=25&sort=-modifiedDate&sfm%5Bstatus%5D%5Bis_active%5D=true&sfm' \216 f'%5BsimpleSearch%5D%5BkeywordRadio%5D=EXACT&sfm%5BsimpleSearch%5D%5BkeywordTags%5D%5B0%5D%5Bkey%5D={elem}' \217 f'&sfm%5BsimpleSearch%5D%5BkeywordTags%5D%5B0%5D%5Bvalue%5D={elem} '218 driver.get(url2)219 wait_for_content()220 date = driver.find_elements(By.XPATH, '//*[@class="sds-field sds-field--stacked"]/div[2]/span')221 for i in date:222 article_date = i.text.split(' ')223 data_list.append([article_date[0], article_date[1].replace(',', ''), article_date[2]])224 title_html = driver.find_elements(By.TAG_NAME, "h3")225 for el in title_html:226 try:227 title = el.find_element(By.TAG_NAME, 'a')228 href = title.get_attribute('href')229 data_list[count_of_ele].append(title.text)230 data_list[count_of_ele].append(href)231 count_of_ele += 1232 except:233 continue234 last_days = last_7_days()235 for el in data_list:236 for single in last_days:237 if el[0] == single[0] and el[1] == single[1] and el[2] == single[2]:238 driver.get(el[4])239 wait_for_content()240 content = driver.page_source241 content_low = content.lower()242 if content_low.find("blockchain") > -1 or content_low.find("crypto ") > -1 or content_low.find(243 "cryptocurrency") > -1 or content_low.find("crypto currency") > -1 or content.lower().find("distributed ledger") > -1:244 global added245 added = True246 payload = {247 "text": "New article found on https://sam.gov with key word: " + elem + " ```" + "Title: "248 + el[3] + " \n" + "Link: " + el[4] + " ```"}249 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"250 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))251 except:252 continue253def ted_europa():254 global added255 for elem in keywords2:256 print(elem)257 url = 'https://ted.europa.eu/TED/search/search.do'258 driver.get(url)259 # driver.maximize_window()260 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")261 try:262 wait_for_content()263 driver.find_element(By.ID, 'clearAll').click()264 wait_for_content()265 except:266 try:267 wait_for_content()268 driver.find_element(By.ID, 'clearAll').click()269 wait_for_content()270 except Exception as e:271 print(e)272 print("clear fail")273 continue274 try:275 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")276 wait_for_content()277 driver.find_element(By.ID, 'textGroup').click()278 wait_for_content()279 except:280 try:281 driver.refresh()282 wait_for_content()283 driver.find_element(By.ID, 'clearAll').click()284 wait_for_content()285 driver.find_element(By.ID, 'textGroup').click()286 wait_for_content()287 except:288 print("text fail")289 continue290 try:291 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")292 wait_for_content()293 driver.find_element(By.ID, 'freeText').send_keys(elem)294 wait_for_content()295 except:296 try:297 wait_for_content()298 driver.find_element(By.ID, 'freeText').send_keys(elem)299 wait_for_content()300 except:301 print("text input fail")302 continue303 try:304 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")305 wait_for_content()306 driver.find_element(By.ID, 'businessOpportunitiesGroup').click()307 wait_for_content()308 except:309 try:310 wait_for_content()311 driver.find_element(By.ID, 'businessOpportunitiesGroup').click()312 wait_for_content()313 except:314 print("business fail")315 pass316 try:317 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")318 wait_for_content()319 driver.find_element(By.ID, 'dateGroup').click()320 except:321 try:322 wait_for_content()323 driver.find_element(By.ID, 'dateGroup').click()324 except:325 print("date fail")326 continue327 year, month, day, day_name, month_name_short, month_name = previous_week_date(7)328 if int(month) < 10:329 month = '0' + month330 if int(day) < 10:331 day = '0' + day332 date = f'{day}/{month}/{year}'333 wait_for_content()334 try:335 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")336 driver.find_element(By.ID, 'DOCUMENT_TYPE').send_keys("'Contract notice', 'Design contest'")337 except:338 print("Contract except")339 try:340 driver.find_element(By.ID, 'DOCUMENT_TYPE').send_keys("'Contract notice', 'Design contest'")341 except:342 print("Big contract except")343 pass344 try:345 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")346 wait_for_content()347 driver.find_element(By.ID, 'publicationDateFrom').send_keys(date)348 except:349 print("Date except")350 try:351 wait_for_content()352 driver.find_element(By.ID, 'publicationDateFrom').send_keys(date)353 except:354 print("Big date except")355 continue356 try:357 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")358 wait_for_content()359 driver.find_element(By.ID, 'dateGroup').click()360 except:361 print("Clicking date except")362 pass363 try:364 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")365 wait_for_content()366 driver.find_element(By.ID, 'search').click()367 except:368 print("Search except")369 try:370 wait_for_content()371 driver.find_element(By.ID, 'search').click()372 except:373 print("Search except")374 try:375 wait_for_content()376 driver.find_element(By.ID, 'search').click()377 except:378 print("Big search except")379 continue380 try:381 driver.find_element(By.CLASS_NAME, 'page-icon.pagelast').click()382 wait_for_content()383 num = driver.find_element(By.CLASS_NAME, 'pager-number.page-number-selected')384 number_of_pages = int(num.text)385 wait_for_content()386 driver.find_element(By.CLASS_NAME, 'pagefirst.page-icon').click()387 for page in range(number_of_pages):388 wait_for_content()389 plus_button = driver.find_elements(By.CLASS_NAME, 'btn.btn-circle.btn-sm.show_hidden_col')390 wait_for_content()391 for button in plus_button:392 wait_for_content()393 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")394 button.click()395 wait_for_content()396 wait_for_content()397 title = driver.find_elements(By.CLASS_NAME, 'bold.glyphicon-minus')398 list_of_titles = []399 list_of_hrefs = []400 for i, el in enumerate(title):401 if i % 2 != 0:402 list_of_titles.append(el.text)403 wait_for_content()404 for j in range(len(list_of_titles)):405 href = driver.find_element(By.XPATH, f'//*[@id="notice"]/tbody/tr[{j * 2 + 1}]/td[2]/a')406 list_of_hrefs.append(href.get_attribute('href'))407 wait_for_content()408 for index in range(len(list_of_titles)):409 driver.get(list_of_hrefs[index])410 wait_for_content()411 content = driver.page_source412 content_low = content.lower()413 if content_low.find("blockchain") > -1 or content_low.find("crypto ") > -1 or content_low.find(414 "cryptocurrency") > -1 or content_low.find("crypto currency") > -1 or content.lower().find(415 "distributed ledger") > -1:416 added = True417 payload = {418 "text": "New article found on https://ted.europa.eu with key word: " + elem + " ```" + "Title: "419 + list_of_titles[index] + " \n" + "Link: " + list_of_hrefs[index] + " ```"}420 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"421 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))422 wait_for_content()423 driver.find_element(By.CLASS_NAME, 'page-icon.pagenext').click()424 except NoSuchElementException:425 wait_for_content()426 plus_button = driver.find_elements(By.CLASS_NAME, 'btn.btn-circle.btn-sm.show_hidden_col')427 for button in plus_button:428 print("I was here", elem)429 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")430 wait_for_content()431 button.click()432 wait_for_content()433 wait_for_content()434 title = driver.find_elements(By.CLASS_NAME, 'bold.glyphicon-minus')435 list_of_titles = []436 list_of_hrefs = []437 for i, el in enumerate(title):438 if i % 2 != 0:439 list_of_titles.append(el.text)440 wait_for_content()441 for j in range(len(list_of_titles)):442 href = driver.find_element(By.XPATH, f'//*[@id="notice"]/tbody/tr[{j * 2 + 1}]/td[2]/a')443 list_of_hrefs.append(href.get_attribute('href'))444 wait_for_content()445 for index in range(len(list_of_titles)):446 driver.get(list_of_hrefs[index])447 wait_for_content()448 content = driver.page_source449 content_low = content.lower()450 if content_low.find("blockchain") > -1 or content_low.find("crypto ") > -1 or content_low.find(451 "cryptocurrency") > -1 or content_low.find("crypto currency") > -1 or content.lower().find(452 "distributed ledger") > -1:453 added = True454 payload = {455 "text": "New article found on https://ted.europa.eu with key word: " + elem + " ```" + "Title: "456 + list_of_titles[index] + " \n" + "Link: " + list_of_hrefs[index] + " ```"}457 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"458 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))459def coe():460 global added461 for elem in keywords2:462 print(elem)463 results = []464 # url = f'https://publicsearch.coe.int/#k={elem}#f=%5B%5D#dfd=7'465 # driver.get(url)466 for word in keywords2:467 if elem != word:468 wait_for_content()469 url = f'https://publicsearch.coe.int/#k=ALL({elem}, {word})#f=%5B%5D#dfd=7'470 driver.get(url)471 wait_for_content()472 titles = driver.find_elements(By.CLASS_NAME, "ms-srch-item-link")473 # wait_for_content()474 for el in titles:475 title = el.get_attribute('title')476 print(title)477 href = el.get_attribute('href')478 print(href)479 results.append(title)480 results.append(href)481 results = list(dict.fromkeys(results))482 print(results)483 if len(results) > 0:484 for i in range(0, len(results), 2):485 added = True486 payload = {487 "text": "New article found on https://www.coe.int/ with key word: " + elem + " ```" + "Title: "488 + results[i] + " \n" + "Link: " + results[i+1] + " ```"}489 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"490 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))491 wait_for_content()492if __name__ == '__main__':493 instant_markets()494 sam_gov()495 ted_europa()496 coe()497 ec_europa()498 if not ec_europa():499 ec_europa()500 if added == False:501 payload = {502 "text": " ```" + "No article have matched the requirements. Nothing to show" + " ```"}503 response = requests.post("https://hooks.slack.com/services/T14NAEEBZ/B038S999Y3W"504 "/aee3kf3xwgnMr0Nq5jKxwXFW", json.dumps(payload))505 driver.quit()

Full Screen

Full Screen

anothergoogle.py

Source:anothergoogle.py Github

copy

Full Screen

...45 br.load('http://www.google.com')46 def can_continuea(abrowser):47 t = get_tree(abrowser)48 return len(t.xpath("//input[@name='q']")) > 049 br.wait_for_content(can_continuea, 60, u'Timeout while loading account data')50 br.fill('input[name="q"]', 'kiorky')51 t = get_tree(br)52 name = [a.attrib['name']53 for a in t.xpath('//input[@type="submit"]')54 if 'google' in a.value.lower()][0]55 # search for the search input control which can change id56 input_sel = "input[name='%s']" % name57 # remodve the search live query ...58 br.native_click('input[name="q"]')59 br.click(input_sel)60 def can_continueb(abrowser):61 t = get_tree(abrowser)62 return len( t.xpath('//*[@id="ires"]')) > 063 br.wait_for_content(can_continueb, 60, u'Timeout while loading account data')64 assert 'cryptelium.net' in br.html65if __name__ == '__main__':66 print(main())...

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