A
A
ave_koty2022-02-05 00:04:15
selenium
ave_koty, 2022-02-05 00:04:15

How to restart session in Selenium (Python)?

How to restart session via python on Selenium? I am using Chrome.

from selenium import webdriver
import time

driver = webdriver.Chrome(
    executable_path=r'chrome\chromedriver.exe',
)

driver.get('https://vk.com/')
time.sleep(5)
driver.quit() #после этой команды браузер резко закрывается, потому что сессия закрылась. Мне нужно запускать новую, потому что цыкл. Просто refresh не подходит.

driver.get('https://vk.com/')


raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=54913): Max retries exceeded with url: /session (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] The connection was not established because the destination computer refused the connection request'))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ave_koty, 2022-02-05
@ave_koty

I answer to myself:
1. Change driver.quit() to driver.close()
2. Then add the command: driver.start_session({})
3. For some reason, the parameters of the last session are not transferred to me. Essentially the same, since the Ids of the sessions are the same. Who can tell, I will be glad! :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question