diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index 6684278a0d84a..369c35b510d01 100644 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -431,13 +431,14 @@ def execute(self, driver_command: str, params: dict = None) -> dict: :Returns: The command's JSON response loaded into a dictionary object. """ + params = self._wrap_value(params) + if self.session_id: if not params: params = {"sessionId": self.session_id} elif "sessionId" not in params: params["sessionId"] = self.session_id - params = self._wrap_value(params) response = self.command_executor.execute(driver_command, params) if response: self.error_handler.check_response(response) diff --git a/py/test/selenium/webdriver/common/print_pdf_tests.py b/py/test/selenium/webdriver/common/print_pdf_tests.py index c40abe6058fb2..46e66cba904ee 100644 --- a/py/test/selenium/webdriver/common/print_pdf_tests.py +++ b/py/test/selenium/webdriver/common/print_pdf_tests.py @@ -51,3 +51,12 @@ def test_valid_params(driver, pages): base64code = driver.print_page(print_options) assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER + + +def test_session_id_is_not_preserved_after_page_is_printed(driver, pages): + print_options = PrintOptions() + print_options.margin_bottom = print_options.margin_top = print_options.margin_left = print_options.margin_right = 0 + assert "sessionId" not in print_options.to_dict() + pages.load("printPage.html") + driver.print_page(print_options=print_options) + assert "sessionId" not in print_options.to_dict()