0

I am trying to iterate over pages having a program List and then I have to select checkbox defined in an image below in order to get the run length of a loop on-page.

But when I am trying to navigate over pages via the next button it will stop clicking on checkboxes and throws me below error.

I have tried with xpath,css selector and id method But all get failed.

DOM element SS along with checkbox highlighted

Line of Code Used-

CheckBoxclick = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#workflow_table > thead > tr > th.first.checkbox-column.checkbox > input"))).click()

Error:-

   File "D:/Vipul Garg Backup/XXXX/TestingPardotExportProgramsData.py", line 74, in <module>
    ProgramsPathlist = getDataForPrograms(RecordsonOnePage,totalnofpages)
  File "D:/Vipul Garg Backup/XXXX/TestingPardotExportProgramsData.py", line 63, in getDataForPrograms
    RecordsonOnePage = getrecordsoNpage()
  File "D:/Vipul Garg Backup/XXXX/TestingPardotExportProgramsData.py", line 42, in 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()
  File "C:\Users\Vipul.Garg\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\Vipul.Garg\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Vipul.Garg\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Vipul.Garg\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
  (Session info: chrome=80.0.3987.122)

But Above Line of Code is Working Intermetantly and throwing error as above.
Any suggestions for this line of code replacement as why I am getting such inconsistency.

Vipul_Garg
  • 43
  • 1
  • 8
  • Please edit your question and add the HTML. – Greg Burghardt Mar 03 '20 at 17:02
  • Does [this discussion](https://stackoverflow.com/questions/56483403/selenium-common-exceptions-webdriverexception-message-invalid-session-id-using/56492149#56492149) helps you? – undetected Selenium Mar 03 '20 at 23:05
  • @debanjan B I have gone through a mentioned discussion and I have tried to implement the same but getting error-->raise MaxRetryError(_pool, url, error or ResponseError(cause))urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=58203): Max retries exceeded with url: /session/55249a6d074546bf325b41dd87f5d62e/url (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it')) – Vipul_Garg Mar 04 '20 at 03:07
  • @DebanjanB can you Pls look into this Question one more time I have changed my error traces. – Vipul_Garg Mar 05 '20 at 07:49

1 Answers1

0

You are using ID of the Table and checkbox is inside that table, so you need to pass locator of the check box.

As there is no id defined for the checkbox, so using xpath to reach the locator like - //input[@type='checkbox']

Tech_ninja
  • 39
  • 7
  • i have tried these options driver.find_elements_by_xpath('//*[@id="workflow_table"]/thead/tr/th[1]/input').click(), WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='checkbox']"))).click(). But nothing worked out – Vipul_Garg Mar 04 '20 at 02:50
  • getting Error-selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id – Vipul_Garg Mar 04 '20 at 02:52
  • Hi, for invalid session id error ,please check compatible version of selenium and driver, which version you are using?Follow this answer https://stackoverflow.com/questions/53739852/selenium-common-exceptions-invalidsessionidexception-using-geckodriver-selenium – Tech_ninja Mar 04 '20 at 06:24
  • Driver is working Fine and it is Compatible with current Python + Selenium. – Vipul_Garg Mar 05 '20 at 04:51
  • I am using Python version as 3.7 and Selenium driver version-3.141.0 and Chrome driver version-81.0.4044.20. I have changed my question and error stack trace a bit, please have a look. – Vipul_Garg Mar 05 '20 at 04:58
  • As per your updated error logs it is showing stale element exception, The reason for this is because the element to which you have referred is removed from the DOM structure. Please use relative locators . – Tech_ninja Mar 06 '20 at 11:28