How to use switch_to_default_content method in SeleniumBase

Best Python code snippet using SeleniumBase

quickbooks-report-dump.py

Source:quickbooks-report-dump.py Github

copy

Full Screen

...45 global driver46 print 'reloading "Report List"'47 find_click('id', 'nav6', '', 10, "Getting reports")48 find_click('id', 'nav601', '', 10, "Going to 'Report List'")49 driver.switch_to_default_content()50 home_frames = driver.find_elements_by_tag_name('iframe')51 driver.switch_to_frame(home_frames[0]) # since the page was reloaded5253# switch to the frame where the menu/s and link/s can be found54def switch_frame():55 global driver56 # below 'print' is TEMPORARY57 print "switching to menu/link frame..."58 driver.switch_to_default_content()59 driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])6061# 05Sep2012 - enable logging62# 25Sep2012 - use os.sep for directory separator63logging.basicConfig(filename=os.getcwd() + os.sep + 'quickbooks_dump.log', level=logging.INFO, format='%(asctime) %(levelname)s : %(message)s')6465# 04Sep2012 - get configurations66cfg = ConfigParser.ConfigParser()67cfg.read('quickbooks-report-dump.cfg')6869url = cfg.get('credentials', 'url')70username = cfg.get('credentials', 'username')71ppword = cfg.get('credentials', 'ppword')7273show_when_starting = cfg.get('prefs', 'show_when_starting')74if show_when_starting == 0:75 bool_show_when_starting = False76else:77 bool_show_when_starting = True7879download_dir = cfg.get('prefs', 'download_dir')80save_to_disk = cfg.get('prefs', 'save_to_disk_immed')8182# 24Sep2012 - get command named used to move/rename file(s) and DIRECTORY separator83# move - for windows84# mv - for linux/unix85mv = cfg.get('prefs', 'move_command')86sep = os.sep8788print mv8990# ec2-107-22-54-11.compute-1.amazonaws.com *YHyttwQNuz9192# set Firefox profile93fp = webdriver.FirefoxProfile()94#fp.set_preference("browser.download.folderList",2)95fp.set_preference("browser.download.manager.showWhenStarting", False) # False96fp.set_preference("browser.download.dir", download_dir)#"C:\Users\josephson\Downloads")97#fp.set_preference("browser.download.dir", os.getcwd())98# 03Sept2012 - Josephson (file type="application/vnd.ms-excel")99fp.set_preference("browser.helperApps.neverAsk.saveToDisk", save_to_disk) #"application/vnd.ms-excel")100101driver = webdriver.Firefox(firefox_profile=fp)102driver.get(url)103# 31Aug2012 - Josephson (testing something on clicking QBOE links)104show_loading(10, "Loading %s" % (url))105106# 04Sep2012 - Josephson (testing the _find_it function)107find_click('name', 'login', username, 2)108109find_click('name', 'password', ppword, 2)110#driver.find_element_by_id('LoginButton').click()111find_click('id', 'LoginButton', '', 60, "Logging in and loading home page. ")112113114# go to first frame, click the 'Reports' tab115home_frames = driver.find_elements_by_tag_name('iframe')116driver.switch_to_frame(home_frames[0])117show_loading(10)118# 'Reports' tab119120#driver.find_element_by_id('nav6').click() 121#show_loading(10, "Getting reports")122find_click('id', 'nav6', '', 10, "Getting reports")123124# the 'Report List' submenu125# driver.find_element_by_id('nav601').click()126find_click('id', 'nav601', '', 10, "Going to 'Report List'")127128#show_loading(10, "Getting the Banking reports")129find_click('id', 'category_BANKING', '', 2, "Getting the Banking reports")130#driver.find_element_by_id('DEPOSIT_DETAIL_reportListLink_Banking').click()131#show_loading(10, "Getting Deposit Details")132find_click('id', 'DEPOSIT_DETAIL_reportListLink_Banking', '', 10, "Getting \"Deposit Details\" Report")133# @TODO: set dates covered (from and to) for the report134# Deposit Detail135136date_macro = driver.find_element_by_id('date_macro')137138date_macro.find_element_by_xpath("//option[@value='all']").click()139driver.find_element_by_id('button_id_b5_run_report_small.gif').click()140show_loading(20, "Running report") # 20 - for the meantime141driver.switch_to_default_content()142show_loading(5)143home_frames = driver.find_elements_by_tag_name('iframe')144driver.switch_to_frame(home_frames[0]) # since the page was reloaded145#time.sleep(5)146driver.find_element_by_id('button_id_b5_excel_small.gif').click()147show_loading(10, "Getting Excel version of report")148149# 07Sep2012 - Josephson150# Go back to 'Report List' to requet for another report...151# 'Accountant and Taxes' - category_ACCOUNTANT152# The rest:153# category_COMPANY, category_CUSTOMERS, category_SALES, category_VENDORS, category_EMPLOYEES, PAYROLL, LISTS154# Journal report - JOURNAL_reportListLink_Accountant & Taxes155# 25Sep2012 - implement reload_report_list156reload_report_list()157# 10Sep2012 - Josephson (other reports)158159find_click('id', 'JOURNAL_reportListLink_Accountant & Taxes', '', 10, "Getting Journal report...") # << change to &amp; ??160161driver.switch_to_default_content()162home_frames = driver.find_elements_by_tag_name('iframe')163driver.switch_to_frame(home_frames[0]) # since the page was reloaded164date_macro = driver.find_element_by_id('date_macro')165date_macro.find_element_by_xpath("//option[@value='all']").click()166driver.find_element_by_id('button_id_b5_run_report_small.gif').click()167show_loading(20, "Running report") # 20 - for the meantime168# driver.switch_to_default_content()169driver.switch_to_default_content()170show_loading(5)171172home_frames = driver.find_elements_by_tag_name('iframe')173driver.switch_to_frame(home_frames[0]) # since the page was reloaded174#time.sleep(5)175excel_button = driver.find_element_by_id('button_id_b5_excel_small.gif')176# get report177excel_button.click()178show_loading(10, "Getting Excel version of Journals' report...")179180# 17Sep2012 - Josephson (get Profit & Loss excel report)181#find_click('id', 'nav6', '', 10, "Getting reports")182#find_click('id', 'nav601', '', 10, "Going to 'Report List'")183#driver.switch_to_default_content()184#home_frames = driver.find_elements_by_tag_name('iframe')185#driver.switch_to_frame(home_frames[0]) # since the page was reloaded186reload_report_list()187find_click('id', 'PANDL_reportListLink_Company', '', 10, "Getting \"Profit & Loss\" report...")188# no need for date_macro FOR NOW189show_loading(10, "Running report")190driver.switch_to_default_content()191home_frames = driver.find_elements_by_tag_name('iframe')192driver.switch_to_frame(home_frames[0]) # since the page was reloaded193show_loading(5)194excel_button = driver.find_element_by_id('button_id_b5_excel_small.gif')195excel_button.click()196show_loading(10, "Getting Excel version of \"Profit & Loss\" report...")197198# Profit and Loss Detail report199#find_click('id', 'nav6', '', 10, "Getting reports")200#find_click('id', 'nav601', '', 10, "Going to 'Report List'")201#driver.switch_to_default_content()202#home_frames = driver.find_elements_by_tag_name('iframe')203#driver.switch_to_frame(home_frames[0]) # since the page was reloaded204reload_report_list()205find_click('id', 'PANDL_DET_reportListLink_Company', '', 20, "Getting \"Profit & Loss Detail\" report...")206driver.switch_to_default_content()207home_frames = driver.find_elements_by_tag_name('iframe')208driver.switch_to_frame(home_frames[0])209driver.find_element_by_id('button_id_b5_excel_small.gif').click()210show_loading(10, "Getting Excel version of \"Profit & Loss Detail\" report...")211212213# 18Sep2012 - Balance Sheet report214#find_click('id', 'nav6', '', 10, "Getting reports")215#find_click('id', 'nav601', '', 10, "Going to 'Report List'")216#driver.switch_to_default_content()217#home_frames = driver.find_elements_by_tag_name('iframe')218#driver.switch_to_frame(home_frames[0]) # since the page was reloaded219reload_report_list()220find_click('id', 'BAL_SHEET_reportListLink_Company', '', 10, "Getting \"Balance Sheet\" report")221driver.switch_to_default_content()222driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])223driver.find_element_by_id('button_id_b5_excel_small.gif').click()224show_loading(10, "Getting Excel version of \"Balance Sheet\" report...")225226#find_click('id', 'nav6', '', 10)227reload_report_list()228find_click('id', 'BAL_SHEET_SUM_reportListLink_Company', '', 10, "Getting \"Balance Sheet Summary\" report")229driver.switch_to_default_content()230driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])231driver.find_element_by_id('button_id_b5_excel_small.gif').click()232show_loading(10, "Getting Excel version of \"Balance Sheet Summary\" report...")233234#find_click('id', 'nav6', '', 10)235reload_report_list()236find_click('id', 'CASH_FLOW_reportListLink_Company', '', 15, "Getting \"Statement of Cash Flows\" report")237driver.switch_to_default_content()238driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])239driver.find_element_by_id('button_id_b5_excel_small.gif').click()240show_loading(10, "Getting Excel version of \"Statement of Cash Flows\"")241242# 20Sep2012 - Account Listing report243#find_click('id', 'nav6', '', 10)244reload_report_list()245find_click('id', 'ACCT_LIST_reportListLink_Company', '', 15, "Getting \"Account Listing\" report")246driver.switch_to_default_content()247driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])248driver.find_element_by_id('button_id_b5_excel_small.gif').click()249show_loading(10, "Getting excel version of \"Account Listing\"")250251252# A/R Aging253#find_click('id', 'nav6', '', 10)254reload_report_list()255find_click('id', 'AR_AGING_reportListLink_Customers', '', 15, "Getting \"A/R Aging Summary\" report")256driver.switch_to_default_content()257driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])258date_macro = driver.find_element_by_id('date_macro')259date_macro.find_element_by_xpath("//option[@value='all']").click()260driver.find_element_by_id('button_id_b5_run_report_small.gif').click()261show_loading(20, "Running report") # 20 - for the meantime262driver.switch_to_default_content()263driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])264driver.find_element_by_id('button_id_b5_excel_small.gif').click()265show_loading(10, "Getting excel version of \"A/R Aging Summary\" report")266267# 27Sep2012 - A/R Aging Detail268reload_report_list()269find_click('id', 'AR_AGING_DET_reportListLink_Customers', '', 15, "Getting \"A/R Aging Detail\" report")270driver.switch_to_default_content()271driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])272date_macro = driver.find_element_by_id('date_macro')273date_macro.find_element_by_xpath("//option[@value='all']").click()274driver.find_element_by_id('button_id_b5_run_report_small.gif').click()275show_loading(20, "Running report") # 20 - for the meantime276driver.switch_to_default_content()277driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])278driver.find_element_by_id('button_id_b5_excel_small.gif').click()279show_loading(10, "Getting excel version of \"A/R Aging Detail\" report")280281282# Customer Balance Summary report283reload_report_list()284find_click('id', 'CUST_BAL_reportListLink_Customers', '', 15, "Getting \"Customer Balance Summary\" report")285switch_frame()286date_macro = driver.find_element_by_id('date_macro')287date_macro.find_element_by_xpath("//option[@value='all']").click()288driver.find_element_by_id('button_id_b5_run_report_small.gif').click()289show_loading(20, "Running report") # 20 - for the meantime290switch_frame() ...

Full Screen

Full Screen

quickbooks-dump.py

Source:quickbooks-dump.py Github

copy

Full Screen

...45 global driver46 print 'reloading "Report List"'47 find_click('id', 'nav6', '', 10, "Getting reports")48 find_click('id', 'nav601', '', 10, "Going to 'Report List'")49 driver.switch_to_default_content()50 home_frames = driver.find_elements_by_tag_name('iframe')51 driver.switch_to_frame(home_frames[0]) # since the page was reloaded5253# switch to the frame where the menu/s and link/s can be found54def switch_frame():55 global driver56 # below 'print' is TEMPORARY57 print "switching to menu/link frame..."58 driver.switch_to_default_content()59 driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])6061# 05Sep2012 - enable logging62# 25Sep2012 - use os.sep for directory separator63logging.basicConfig(filename=os.getcwd() + os.sep + 'quickbooks_dump.log', level=logging.INFO, format='%(asctime) %(levelname)s : %(message)s')6465# 04Sep2012 - get configurations66cfg = ConfigParser.ConfigParser()67cfg.read('dump_casc_qboe_other.cfg')6869url = cfg.get('credentials', 'url')70username = cfg.get('credentials', 'username')71ppword = cfg.get('credentials', 'ppword')7273show_when_starting = cfg.get('prefs', 'show_when_starting')74if show_when_starting == 0:75 bool_show_when_starting = False76else:77 bool_show_when_starting = True7879download_dir = cfg.get('prefs', 'download_dir')80save_to_disk = cfg.get('prefs', 'save_to_disk_immed')8182# 24Sep2012 - get command named used to move/rename file(s) and DIRECTORY separator83# move - for windows84# mv - for linux/unix85mv = cfg.get('prefs', 'move_command')86sep = os.sep8788print mv8990# ec2-107-22-54-11.compute-1.amazonaws.com *YHyttwQNuz9192# set Firefox profile93fp = webdriver.FirefoxProfile()94#fp.set_preference("browser.download.folderList",2)95fp.set_preference("browser.download.manager.showWhenStarting", False) # False96fp.set_preference("browser.download.dir", download_dir)#"C:\Users\josephson\Downloads")97#fp.set_preference("browser.download.dir", os.getcwd())98# 03Sept2012 - Josephson (file type="application/vnd.ms-excel")99fp.set_preference("browser.helperApps.neverAsk.saveToDisk", save_to_disk) #"application/vnd.ms-excel")100101driver = webdriver.Firefox(firefox_profile=fp)102driver.get(url)103# 31Aug2012 - Josephson (testing something on clicking QBOE links)104show_loading(10, "Loading %s" % (url))105106# 04Sep2012 - Josephson (testing the _find_it function)107find_click('name', 'login', username, 2)108109find_click('name', 'password', ppword, 2)110#driver.find_element_by_id('LoginButton').click()111find_click('id', 'LoginButton', '', 60, "Logging in and loading home page. ")112113114# go to first frame, click the 'Reports' tab115home_frames = driver.find_elements_by_tag_name('iframe')116driver.switch_to_frame(home_frames[0])117show_loading(10)118# 'Reports' tab119120#driver.find_element_by_id('nav6').click() 121#show_loading(10, "Getting reports")122find_click('id', 'nav6', '', 10, "Getting reports")123124# the 'Report List' submenu125# driver.find_element_by_id('nav601').click()126find_click('id', 'nav601', '', 10, "Going to 'Report List'")127128#show_loading(10, "Getting the Banking reports")129find_click('id', 'category_BANKING', '', 2, "Getting the Banking reports")130#driver.find_element_by_id('DEPOSIT_DETAIL_reportListLink_Banking').click()131#show_loading(10, "Getting Deposit Details")132find_click('id', 'DEPOSIT_DETAIL_reportListLink_Banking', '', 10, "Getting \"Deposit Details\" Report")133# @TODO: set dates covered (from and to) for the report134# Deposit Detail135136date_macro = driver.find_element_by_id('date_macro')137138date_macro.find_element_by_xpath("//option[@value='all']").click()139driver.find_element_by_id('button_id_b5_run_report_small.gif').click()140show_loading(20, "Running report") # 20 - for the meantime141driver.switch_to_default_content()142show_loading(5)143home_frames = driver.find_elements_by_tag_name('iframe')144driver.switch_to_frame(home_frames[0]) # since the page was reloaded145#time.sleep(5)146driver.find_element_by_id('button_id_b5_excel_small.gif').click()147show_loading(10, "Getting Excel version of report")148149# 07Sep2012 - Josephson150# Go back to 'Report List' to requet for another report...151# 'Accountant and Taxes' - category_ACCOUNTANT152# The rest:153# category_COMPANY, category_CUSTOMERS, category_SALES, category_VENDORS, category_EMPLOYEES, PAYROLL, LISTS154# Journal report - JOURNAL_reportListLink_Accountant & Taxes155# 25Sep2012 - implement reload_report_list156reload_report_list()157# 10Sep2012 - Josephson (other reports)158159find_click('id', 'JOURNAL_reportListLink_Accountant & Taxes', '', 10, "Getting Journal report...") # << change to &amp; ??160161driver.switch_to_default_content()162home_frames = driver.find_elements_by_tag_name('iframe')163driver.switch_to_frame(home_frames[0]) # since the page was reloaded164date_macro = driver.find_element_by_id('date_macro')165date_macro.find_element_by_xpath("//option[@value='all']").click()166driver.find_element_by_id('button_id_b5_run_report_small.gif').click()167show_loading(20, "Running report") # 20 - for the meantime168# driver.switch_to_default_content()169driver.switch_to_default_content()170show_loading(5)171172home_frames = driver.find_elements_by_tag_name('iframe')173driver.switch_to_frame(home_frames[0]) # since the page was reloaded174#time.sleep(5)175excel_button = driver.find_element_by_id('button_id_b5_excel_small.gif')176# get report177excel_button.click()178show_loading(10, "Getting Excel version of Journals' report...")179180# 17Sep2012 - Josephson (get Profit & Loss excel report)181#find_click('id', 'nav6', '', 10, "Getting reports")182#find_click('id', 'nav601', '', 10, "Going to 'Report List'")183#driver.switch_to_default_content()184#home_frames = driver.find_elements_by_tag_name('iframe')185#driver.switch_to_frame(home_frames[0]) # since the page was reloaded186reload_report_list()187find_click('id', 'PANDL_reportListLink_Company', '', 10, "Getting \"Profit & Loss\" report...")188# no need for date_macro FOR NOW189show_loading(10, "Running report")190driver.switch_to_default_content()191home_frames = driver.find_elements_by_tag_name('iframe')192driver.switch_to_frame(home_frames[0]) # since the page was reloaded193show_loading(5)194excel_button = driver.find_element_by_id('button_id_b5_excel_small.gif')195excel_button.click()196show_loading(10, "Getting Excel version of \"Profit & Loss\" report...")197198# Profit and Loss Detail report199#find_click('id', 'nav6', '', 10, "Getting reports")200#find_click('id', 'nav601', '', 10, "Going to 'Report List'")201#driver.switch_to_default_content()202#home_frames = driver.find_elements_by_tag_name('iframe')203#driver.switch_to_frame(home_frames[0]) # since the page was reloaded204reload_report_list()205find_click('id', 'PANDL_DET_reportListLink_Company', '', 20, "Getting \"Profit & Loss Detail\" report...")206driver.switch_to_default_content()207home_frames = driver.find_elements_by_tag_name('iframe')208driver.switch_to_frame(home_frames[0])209driver.find_element_by_id('button_id_b5_excel_small.gif').click()210show_loading(10, "Getting Excel version of \"Profit & Loss Detail\" report...")211212213# 18Sep2012 - Balance Sheet report214#find_click('id', 'nav6', '', 10, "Getting reports")215#find_click('id', 'nav601', '', 10, "Going to 'Report List'")216#driver.switch_to_default_content()217#home_frames = driver.find_elements_by_tag_name('iframe')218#driver.switch_to_frame(home_frames[0]) # since the page was reloaded219reload_report_list()220find_click('id', 'BAL_SHEET_reportListLink_Company', '', 10, "Getting \"Balance Sheet\" report")221driver.switch_to_default_content()222driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])223driver.find_element_by_id('button_id_b5_excel_small.gif').click()224show_loading(10, "Getting Excel version of \"Balance Sheet\" report...")225226#find_click('id', 'nav6', '', 10)227reload_report_list()228find_click('id', 'BAL_SHEET_SUM_reportListLink_Company', '', 10, "Getting \"Balance Sheet Summary\" report")229driver.switch_to_default_content()230driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])231driver.find_element_by_id('button_id_b5_excel_small.gif').click()232show_loading(10, "Getting Excel version of \"Balance Sheet Summary\" report...")233234#find_click('id', 'nav6', '', 10)235reload_report_list()236find_click('id', 'CASH_FLOW_reportListLink_Company', '', 15, "Getting \"Statement of Cash Flows\" report")237driver.switch_to_default_content()238driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])239driver.find_element_by_id('button_id_b5_excel_small.gif').click()240show_loading(10, "Getting Excel version of \"Statement of Cash Flows\"")241242# 20Sep2012 - Account Listing report243#find_click('id', 'nav6', '', 10)244reload_report_list()245find_click('id', 'ACCT_LIST_reportListLink_Company', '', 15, "Getting \"Account Listing\" report")246driver.switch_to_default_content()247driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])248driver.find_element_by_id('button_id_b5_excel_small.gif').click()249show_loading(10, "Getting excel version of \"Account Listing\"")250251252# A/R Aging253#find_click('id', 'nav6', '', 10)254reload_report_list()255find_click('id', 'AR_AGING_reportListLink_Customers', '', 15, "Getting \"A/R Aging Summary\" report")256driver.switch_to_default_content()257driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])258date_macro = driver.find_element_by_id('date_macro')259date_macro.find_element_by_xpath("//option[@value='all']").click()260driver.find_element_by_id('button_id_b5_run_report_small.gif').click()261show_loading(20, "Running report") # 20 - for the meantime262driver.switch_to_default_content()263driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])264driver.find_element_by_id('button_id_b5_excel_small.gif').click()265show_loading(10, "Getting excel version of \"A/R Aging Summary\" report")266267# 27Sep2012 - A/R Aging Detail268reload_report_list()269find_click('id', 'AR_AGING_DET_reportListLink_Customers', '', 15, "Getting \"A/R Aging Detail\" report")270driver.switch_to_default_content()271driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])272date_macro = driver.find_element_by_id('date_macro')273date_macro.find_element_by_xpath("//option[@value='all']").click()274driver.find_element_by_id('button_id_b5_run_report_small.gif').click()275show_loading(20, "Running report") # 20 - for the meantime276driver.switch_to_default_content()277driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])278driver.find_element_by_id('button_id_b5_excel_small.gif').click()279show_loading(10, "Getting excel version of \"A/R Aging Detail\" report")280281282# Customer Balance Summary report283reload_report_list()284find_click('id', 'CUST_BAL_reportListLink_Customers', '', 15, "Getting \"Customer Balance Summary\" report")285switch_frame()286date_macro = driver.find_element_by_id('date_macro')287date_macro.find_element_by_xpath("//option[@value='all']").click()288driver.find_element_by_id('button_id_b5_run_report_small.gif').click()289show_loading(20, "Running report") # 20 - for the meantime290switch_frame() ...

Full Screen

Full Screen

ga.py

Source:ga.py Github

copy

Full Screen

...21driver = webdriver.Firefox(firefox_profile=firefox_profile) # Use chrome driver22screenNum=123def screenshot():24 global screenNum25 driver.switch_to_default_content()26 driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))27 driver.get_screenshot_as_file(desktop + str(screenNum) + ".png")28 screenNum += 129 driver.switch_to_default_content()30def clickID(sel, sleep=3):31 try:32 driver.find_element_by_id(sel).click()33 time.sleep(sleep)34 except Exception:35 time.sleep(sleep)36 print("retrying... " + sel)37 try:38 # Randomly click on the void spaces39 if bool(random.getrandbits(1)):40 driver.switch_to_default_content()41 driver.find_element_by_id("ga-nav-collapse").click()42 else:43 driver.switch_to_default_content()44 driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))45 except:46 pass47 clickID(sel)48 pass49def clickName(sel, sleep=3):50 try:51 driver.find_element_by_name(sel).click()52 time.sleep(sleep)53 except Exception:54 time.sleep(sleep)55 print("retrying... " + sel)56 try:57 # Randomly click on the void spaces58 if bool(random.getrandbits(1)):59 driver.switch_to_default_content()60 driver.find_element_by_id("ga-nav-collapse").click()61 else:62 driver.switch_to_default_content()63 driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))64 except:65 pass66 clickName(sel)67 pass68def clickXpath(sel, sleep=3):69 try:70 driver.find_element_by_xpath(sel).click()71 time.sleep(sleep)72 except Exception:73 time.sleep(sleep)74 print("retrying..." + sel)75 try:76 # Randomly click on the void spaces77 if bool(random.getrandbits(1)):78 driver.switch_to_default_content()79 driver.find_element_by_id("ga-nav-collapse").click()80 else:81 driver.switch_to_default_content()82 driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))83 except:84 pass85 clickXpath(sel)86 pass87def clickText(sel, sleep=3):88 try:89 driver.find_element_by_link_text(sel).click()90 time.sleep(sleep)91 except Exception:92 time.sleep(sleep)93 print("retrying..." + sel)94 try:95 # Randomly click on the void spaces96 if bool(random.getrandbits(1)):97 driver.switch_to_default_content()98 driver.find_element_by_id("ga-nav-collapse").click()99 else:100 driver.switch_to_default_content()101 driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))102 except:103 pass104 clickText(sel)105 pass106driver.maximize_window()107driver.get("https://analytics.google.com/analytics/web")108# driver.get("https://accounts.google.com/signin/v2/identifier?service=analytics&passive=1209600&continue=https%3A%2F%2Fanalytics.google.com%2Fanalytics%2Fweb%2F%23&followup=https%3A%2F%2Fanalytics.google.com%2Fanalytics%2Fweb%2F&flowName=GlifWebSignIn&flowEntry=ServiceLogin")109clickID("identifierId")110driver.find_element_by_id("identifierId").clear()111driver.find_element_by_id("identifierId").send_keys("joeky_zhan@asus.com")112clickID("identifierNext")113# clickXpath("(.//*[normalize-space(text()) and normalize-space(.)='Learn more'])[1]/following::content[1]")114clickName("password")115driver.find_element_by_name("password").clear()116PASS=""117driver.find_element_by_name("password").send_keys(PASS)118clickID("passwordNext")119# clickXpath("(.//*[normalize-space(text()) and normalize-space(.)='joeky_zhan@asus.com'])[1]/following::span[1]")120clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='載入中...'])[1]/following::div[4]")121clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='載入中...'])[1]/following::button[2]")122clickXpath("(.//*[normalize-space(text()) and normalize-space(.)='UA-73282159-35'])[1]/following::span[2]")123clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資料檢視'])[1]/following::div[6]")124clickText(u"總覽")125clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")126screenshot()127clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='載入中...'])[1]/following::div[4]")128clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='總覽'])[2]/following::span[1]")129driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))130time.sleep(3)131checkboxes = driver.find_elements_by_css_selector('span.W_CHECKABLE')132checkboxes.pop(0)133for checkbox in checkboxes:134 while True:135 time.sleep(2)136 try:137 checkbox.click()138 break139 except Exception: # Replace Exception with something more specific.140 print("retrying... checkboxes")141 continue142screenshot()143driver.switch_to_default_content()144clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='總覽'])[1]/following::span[1]")145clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資訊主頁'])[1]/following::span[1]")146driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))147clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='建立日期'])[1]/following::div[4]")148driver.switch_to_default_content()149clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")150screenshot()151clickID("ga-nav-collapse")152clickText(u"行為")153clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='行為'])[1]/following::a[1]")154clickID("ga-nav-collapse")155screenshot()156# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]157driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))158clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='事件總數'])[5]/following::div[1]")159clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='平均價值'])[4]/following::span[2]")160clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='活動標籤'])[1]/following::div[10]")161screenshot()162# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]163clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")164# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]165driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))166clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='活動標籤'])[1]/following::div[10]")167clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='事件類別:'])[1]/following::div[3]")168clickXpath("(.//*[normalize-space(text()) and normalize-space(.)='Model'])[1]/following::div[1]")169screenshot()170driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))171clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='事件類別:'])[1]/following::div[2]")172clickXpath("(.//*[normalize-space(text()) and normalize-space(.)='DSAPI_Result'])[1]/following::div[1]")173screenshot()174# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]175clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='載入中...'])[1]/following::button[2]")176clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資源和應用程式'])[1]/following::div[6]")177clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資料檢視'])[1]/following::div[6]")178# clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='所有行動應用程式資料'])[1]/following::span[1]")179clickText(u"總覽")180clickID("ga-nav-collapse")181screenshot()182clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='總覽'])[2]/following::span[1]")183# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]184driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))185time.sleep(3)186checkboxes = driver.find_elements_by_css_selector('span.W_CHECKABLE')187time.sleep(3)188checkboxes.pop(0)189for checkbox in checkboxes:190 while True:191 time.sleep(2)192 try:193 checkbox.click()194 break195 except Exception: # Replace Exception with something more specific.196 print("retrying... checkboxes")197 continue198screenshot()199clickID("ga-nav-collapse")200clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")201clickText(u"自訂")202clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資訊主頁'])[1]/following::span[1]")203driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))204clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='建立日期'])[1]/following::div[4]")205driver.switch_to_default_content()206clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")207# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]208screenshot()209clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='小時'])[1]/following::div[10]")210# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]211clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")212screenshot()213clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='客戶開發'])[1]/following::span[1]")214clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='總覽'])[2]/following::span[1]")215clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")216screenshot()217# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]218clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='顯示列數:'])[1]/following::select[1]")219clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='顯示列數:'])[1]/following::option[4]")220# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]221clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='載入中...'])[1]/following::button[2]")222clickXpath("(.//*[normalize-space(text()) and normalize-space(.)='Robot-userdebug'])[1]/following::div[3]")223clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資源和應用程式'])[1]/following::div[6]")224clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='所有網站資料'])[1]/following::span[1]")225clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='即時'])[1]/following::span[1]")226clickText(u"總覽")227clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")228screenshot()229clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='總覽'])[1]/following::span[1]")230clickID("ga-nav-collapse")231# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]232# clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='活躍使用者'])[5]/following::span[4]")233# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]234# clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::ga-galaxy-page[1]")235# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]236driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))237time.sleep(3)238checkboxes = driver.find_elements_by_css_selector('span.W_CHECKABLE')239time.sleep(3)240checkboxes.pop(0)241for checkbox in checkboxes:242 while True:243 time.sleep(2)244 try:245 checkbox.click()246 break247 except Exception: # Replace Exception with something more specific.248 print("retrying... checkboxes")249 continue250screenshot()251# clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='活躍使用者'])[5]/following::span[6]")252# clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='活躍使用者'])[5]/following::span[8]")253# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]254clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")255clickText(u"自訂")256clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='資訊主頁'])[1]/following::span[1]")257# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]258driver.switch_to.frame(driver.find_element_by_id("galaxyIframe"))259clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='建立日期'])[1]/following::div[4]")260# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]261driver.switch_to_default_content()262clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='管理'])[1]/following::md-icon[1]")263# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]264clickXpath(u"(.//*[normalize-space(text()) and normalize-space(.)='小時'])[1]/following::div[10]")265screenshot()266# Execute this bash command267# $ find . -name '*' -type f -exec mv {} ./ \; && find . -type d -empty -delete268# Or the Powershell Command...

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