Selenium python-Getting timeout error even after handling it -
i automating application downloads files using selenium , python. getting timeout exception though have handled in python script. timeout exception handles timeout of time code crashes. below script please suggest how can avoid timeout exception in order make script more robust. 1st part of code launch application , reach until point clicks file downloaded. each page has 20 files downloaded , candidate function each page.
from selenium import webdriver selenium.webdriver.common.keys import keys selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec selenium.common.exceptions import timeoutexception chromeoptions = webdriver.chromeoptions() prefs = {"download.default_directory" : "location"} chromeoptions.add_experimental_option("prefs",prefs) driver=webdriver.chrome("\\chromedriver.exe",chrome_options=chromeoptions) driver.implicitly_wait(30) driver.maximize_window() driver.implicitly_wait(100) driver.get("url") username=driver.find_element_by_id("user") username.clear() username.send_keys("mmnba") password=driver.find_element_by_id("pw") password.clear() password.send_keys("dfsdf") driver.implicitly_wait(20) login=driver.find_element_by_id("loginbutton") login.click() driver.implicitly_wait(20) rollup=driver.find_element_by_xpath("") rollup.click() driver.switch_to.frame(0) link=driver.find_element_by_xpath("//td[@id="""") link.click() driver.implicitly_wait(20) pagelist=driver.find_elements_by_xpath("") def candidate(): global k,page_num,driver j in range(0,20): try: driver.implicitly_wait(50) employeelist=driver.find_elements_by_xpath("") employeelist[j].click() driver.switch_to_default_content() driver.implicitly_wait(50) driver.switch_to.frame("detail") wait = webdriverwait(driver,20) resume = wait.until(ec.presence_of_element_located((by.xpath,""))) driver.implicitly_wait(50) resume.click() download = wait.until(ec.presence_of_element_located((by.xpath,'//a[@title="download resume"]'))) driver.implicitly_wait(50) download.click() driver.implicitly_wait(50) driver.switch_to.frame("rtfviewer_ms") msword = wait.until(ec.presence_of_element_located((by.xpath,""))) driver.implicitly_wait(50) msword.click() except timeoutexception ex1: print("exception has been thrown"+str(ex1)) print(j) driver.switch_to_default_content() driver.switch_to.frame(0) continue # code moving 1 page next k=0 page_num=0 candidate() pagelist=driver.find_elements_by_xpath("") in range(0,10): driver.implicitly_wait(50) pagelist=driver.find_elements_by_xpath("") if !=9: page_num=i print("page number "+str(page_num)) pagelist[i].click() candidate() if i==9: k=1 pagelist=driver.find_elements_by_xpath("") i=1 page_num=i while i<12: driver.implicitly_wait(50) pagelist=driver.find_elements_by_xpath("") if ==10: pagelist[i].click() candidate() k=k+1 print("k "+str(k)) i=1 page_num=i else: page_num=i print("page number "+str(page_num)) pagelist[i].click() candidate() i=i+1 #edit : adding traceback traceback (most recent call last): file "<ipython-input-7-f663f73d040e>", line 1, in <module> runfile('d:/automate_v6.py', wdir='d:/') file "c:\users\vishnu\anaconda2\lib\site- packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile execfile(filename, namespace) file "c:\users\vishnu\anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) file "d:/automate_v6.py", line 214, in <module> candidate() file "d:/automate_v6.py", line 177, in candidate driver.switch_to_default_content() file "c:\users\vishnu\anaconda2\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 575, in switch_to_default_content self._switch_to.default_content() file "c:\users\vishnu\anaconda2\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\switch_to.py", line 52, in default_content self._driver.execute(command.switch_to_frame, {'id': none}) file "c:\users\vishnu\anaconda2\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 233, in execute self.error_handler.check_response(response) file "c:\users\vishnu\anaconda2\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) timeoutexception: timeout (session info: chrome=60.0.3112.101) (driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=windows nt 10.0.14393 x86_64)
Comments
Post a Comment