Reputation: 43
I am getting Error of selenium.common.exceptions.InvalidSessionIdException: Message: invalid session-id as soon as I am trying to find CheckboxClick web Element from inside a Function call defined in try block and when I placed below line of code outside the function and try block it will not throw me any error.
Line of Code
try:
def getrecordsoNpage():
**CheckBoxclick = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#workflow_table > thead > tr > th.first.checkbox-column.checkbox > input"))).click()**
RecordsonOnePage = int(driver.find_element_by_css_selector('#wf_table_footer > form.inline.pull-left > div > label > span').text)
pprint.pprint(RecordsonOnePage)
totalnofpages = math.ceil(TotalNofRecord / RecordsonOnePage)
print(totalnofpages)
return RecordsonOnePage,totalnofpages
except RuntimeError as e:
pprint.pprint(e)
finally:
driver.close()
# driver.quit()
RecordsonOnePage,totalnofpages = getrecordsoNpage()
pprint.pprint(RecordsonOnePage,totalnofpages)
Can Somebody please suggest why it is acting like that and ways I can correct that I have searched for Invalid session-id error and tried to dispose session id but getting the error as explained above.
Upvotes: 0
Views: 3532
Reputation: 43
I have removed my function inside Try block and have placed try block inside my function and it helped to rectify that error and moreover the primary reason the error arose when we were using the driver after closing it.
Upvotes: 1