How to use js_click_all method in SeleniumBase

Best Python code snippet using SeleniumBase

http_request_infor.py

Source:http_request_infor.py Github

copy

Full Screen

1# import urllib.request as req2# import requests3# url = 'https://api.nasdaq.com/api/quote/AMZN/option-chain?assetclass=stocks&limit=99999'4# # url = 'https://au.finance.yahoo.com/quote/AMZN/options?p=AMZN'5# # urllib.request.urlopen(url, ).read()6# try:7 8# # reqURL = req.Request(url)9# resp = requests.get(url, timeout=10)10# resp_data = resp.text11# with open('data.txt','a') as f:12# f.write(resp_data)13# f.close()14# except e:15# print(e)16# except (HTTPError, URLError) as error:17# logging.error(18# 'Data of %s not retrieved because %s\nURL: %s', name, error, url)19# https://api.nasdaq.com/api/quote/AMZN/option-chain?assetclass=stocks&limit=60&fromdate=2021-06-18&todate=2021-06-18&excode=oprac&callput=callput&money=at&type=all20# https://api.nasdaq.com/api/quote/AMZN/option-chain?assetclass=stocks&limit=9999921# 'https://api.nasdaq.com/api/quote/AMZN/option-chain?assetclass=stocks&limit=99999&fromdate=all&todate=undefined&excode=oprac&callput=callput&money=all&type=all'22# =======================================================23from selenium import webdriver24from selenium.webdriver.common.keys import Keys25from selenium.webdriver.common.by import By26from selenium.webdriver.support.ui import WebDriverWait27from selenium.webdriver.support import expected_conditions as EC28from bs4 import BeautifulSoup as bs 29import _datetime30import time31today = _datetime.date.today()32PATH = '/c/Users/gordon/Desktop/codeVault/report_system/test_automation/py_auto_folder/chromedriver'33driver = webdriver.Chrome(PATH)34wait = WebDriverWait(driver, 60)35driver.get("https://api.nasdaq.com/api/quote/AMZN/option-chain?assetclass=stocks&limit=99999&fromdate=all&todate=undefined&excode=oprac&callput=callput&money=all&type=all")36time.sleep(5)37driver.quit()38# js_click_dropdown = "document.querySelector('span.caret').click()"39# js_click_all = "document.querySelector('div.dropdown-menu').children[3].click()"40# js_all_tr = "return document.querySelector('tbody').innerHTML"41# filename = f"{today}_pwcJobs.csv"42# f = open(filename, "w")43# headers = "job_id,job_title,job_title_link,location,line_of_service,specialism,industry,grade,apply_link,learn_more_link\n"44# f.write(headers)45# try:46# wait.until(EC.presence_of_element_located((By.CLASS_NAME, "caret")))47# spans = driver.find_elements_by_tag_name("span")48 49# driver.execute_script(js_click_dropdown)50# driver.execute_script(js_click_all)51# html = driver.execute_script(js_all_tr)52 53# html_tr = bs(html, 'html.parser')54# trs = html_tr.findAll("tr")55# print(f"TR len is {len(trs)}")56# for tr in trs:57# tds = tr.findAll("td")58 59# job_title = tds[0].a.text.replace(",","")60# job_title_link = tds[0].a['href']61# location = tds[1].text.replace(",","")62# line_of_service = tds[2].text.replace(",","")63# specialism = tds[3].text.replace(",","")64# industry = tds[4].text.replace(",","")65# grade = tds[5].text.replace(",","")66# apply_learn_links_a_tag = tds[6].findAll("a")67# apply_link_tag = apply_learn_links_a_tag[0]68# learn_more_tag = apply_learn_links_a_tag[1]69# job_id = apply_link_tag.get('data-id')70# apply_link = apply_link_tag.get('href')71# learn_more_link = learn_more_tag.get('href')72# # print(job_title)73# # print(job_title_link)74# # print(location)75# # print(line_of_service)76# # print(specialism)77# if industry is not "" and "Not Applicable":78# # print(f"{industry}")79# write_industry = industry80# else:81# # print("Null")82# write_industry = "NULL"83# print(grade)84# if job_id is not None:85# # print(f"Job Id is {job_id}")86# # print(f"Apply Link is {apply_link}")87# write_job_id = job_id.replace(",","")88# write_apply_link = apply_link.replace(",","")89# # print("")90# else:91# # print("Job Id is empty")92# write_job_id = "NULL"93# write_apply_link = "NULL"94# # print("")95# if learn_more_link is not None:96# # print(f"Learn More link is {learn_more_link}")97# write_learn_more_link = learn_more_link.replace(",","")98# # print("")99# else:100# # print("No link on Learn More")101# write_learn_more_link = "NULL"102# # print("")103# print("")104 105# f.write(f"{write_job_id},{job_title},{job_title_link},{location},{line_of_service},{specialism},{write_industry},{grade},{write_apply_link},{write_learn_more_link}\n")106# print("")107 108# except Exception as ex:109# if hasattr(ex, 'message'):110# print(ex.message)111# else:112# print(ex)113# print("not working")114# driver.quit()115# f.close()116# finally:117# driver.quit()...

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