def fileEnumer(): global driver,prevTrail,modelName CSS=driver.find_element_by_css_selector CSSs=driver.find_elements_by_css_selector try: try: waitClickable('#lisupport a',15,1.6).click() except TimeoutException: driver.save_screenshot('asus_no_firmware_download.png') ulog('No firmware download for "%s" !'%modelName) return enterFrame('ifame_auto_size') # click 'Driver & Tools' waitClickable('#a_support_tab_Download',40,2).click() # switch to frame enterFrame('ifame_auto_size') # open dropdown list to select "Others" OS waitClickable('#mainzone_Download2_btn_select_os',10,1).click() retryA(lambda:elemWithText('ul.dropdown-menu.os a', "Others").click()) try: # expand firmware dropdown waitClickable('#btn_type_20',20,1).click() except TimeoutException: driver.save_screenshot('asus_no_firmware_download_2.png') ulog('No firmware download for" %s"!'%modelName) return # retryA(lambda:elemWithText('#download a','Firmware').click(), 20,1) waitUntilStable('#div_type_20',3,0.4) tables = [_ for _ in CSSs('#div_type_20 table') if getElemText(_).startswith('Description')] numTables = len(tables) ulog('numTables=%s'%numTables) versions = [getElemText(_) for _ in CSSs('#div_type_20 p')] assert len(versions)==numTables pageUrl=driver.current_url startIdx = getStartIdx() for idx in range(startIdx, numTables): desc = tables[idx].text relDate = guessDate(desc) fileSize = guessFileSize(desc) fwVer = guessVersion(versions[idx]) fileUrl = tables[idx].find_element_by_css_selector('a').get_attribute('href') trailStr=str(prevTrail+[idx]) sql("INSERT OR REPLACE INTO TFiles(" " model, fw_ver, rel_date, file_size, fw_desc, " " page_url, file_url, tree_trail) VALUES" "(:modelName,:fwVer,:relDate, :fileSize, :desc," ":pageUrl, :fileUrl, :trailStr)", glocals()) ulog('UPSERT "%(modelName)s", "%(fwVer)s", "%(relDate)s", ' '%(fileSize)s, "%(fileUrl)s", %(trailStr)s '%glocals()) except Exception as ex: ipdb.set_trace() traceback.print_exc() driver.save_screenshot(getScriptName()+'_'+getFuncName()+'_excep.png')
def selectSoftwareType(): """ This page would be jumped to versionWalker() or either jumped back to treeWalker forward: may auto jump backward: not auto jump """ global startTrail,prevTrail,driver try: waitText('.csProductSelectorBreadcrumb', 5, 1) waitUntilStable('.csProductSelectorBreadcrumb', 1, 0.3) depth = getDepth() jumpedLevels =depth - len(prevTrail) ulog('jumpedLevels=%d'%jumpedLevels) assert jumpedLevels>=0 ulog('depth=%d, but prevTrail=%s'%(depth, prevTrail)) startIdxFromStartTrail=False def getStartIdx()->int: if startTrail: nonlocal startIdxFromStartTrail startIdxFromStartTrail=True return startTrail.pop(0) else: return 0 if jumpedLevels>0: while depth>len(prevTrail): startIdx=getStartIdx() prevTrail+=[startIdx] else: startIdx=getStartIdx() assert depth==len(prevTrail) ulog('startTrail=%s'%startTrail) ulog('prevTrail=%s'%prevTrail) ulog('startIdx=%d'%startIdx) ulog('url=%s'%driver.current_url) crumbs = waitText('.csProductSelectorBreadcrumb') uprint('crumbs=%s'%(crumbs.replace('\n',' > '))) if not hasElem('table#imageTableContainer', 1.5,0.4): if jumpedLevels>0: startIdx=getStartIdx() if depth > len(prevTrail): prevTrail+=[startIdx] sdpBannerTitle=waitText('td.SDPBannerTitle').strip() ulog('SDBBannerTitle="%s"'%sdpBannerTitle) assert sdpBannerTitle.lower().startswith('select ') waitUntil(lambda: getNumElem('div.csWrapper li a') > 0) swtypes = getElems('div.csWrapper li a') ulog('%s'%[(i,getElemText(_)) for i,_ in enumerate(swtypes)]) numSwTypes=len(swtypes) assert numSwTypes > 0 for idx in range(startIdx, numSwTypes): ulog('goto Trail=%s'%(prevTrail+[idx])) swtypes = getElems('div.csWrapper li a') ulog('Click "%s"'% getElemText(swtypes[idx])) clickElem(swtypes[idx]) prevTrail+=[idx] selectSoftwareType() prevTrail.pop() # Select a Product -> Select a Software type -> Select a Platform # https://software.cisco.com/download/type.html?mdfid=277873153&flowid=170&softwareid=283724313 # Downloads Home >Products >Cisco Interfaces and Modules >WAN Interface Cards >1700/2600/3600/3700 Series 2-Port Analog Modem WAN Interface Card >Analog Firmware Loader >Windows 2000-v6780 # not auto back to treeWalker # go back manually crumbs = getElems('.csProductSelectorBreadcrumb a') ulog('manually backto "%s"'%getElemText(crumbs[-1])) ulog('prevTail=%s'%prevTrail) clickElem(crumbs[-1]) # do I need to pop prevTrail? # prevTrail.pop() else: ulog('auto forward to versionWalker') if startIdxFromStartTrail: startTrail.insert(0, startIdx) for i in range(jumpedLevels): if not startTrail: break startTrail.pop(0) versionWalker() for i in range(jumpedLevels): crumbs = getElems('.csProductSelectorBreadcrumb a') ulog('manually backto "%s"'%getElemText(crumbs[-1])) ulog('prevTail=%s'%prevTrail) clickElem(crumbs[-1]) prevTrail.pop() except Exception as ex: ipdb.set_trace() print(ex); traceback.print_exc() driver.save_screenshot('cisco_selectSoftwareType.png')