Selenium takes over the already open Chrome browser

Selenium takes over the already open Chrome browser

1. Create a folder

Create a folder on the computer's D drive.
For example: A folder named "AutomationProfile" is created on the D drive, and the path is D:\AutomationProfile

2. Find the path of Google Chrome

Right-click on the Google Chrome shortcut, select Properties, and open the location of the file

insert image description here

3. Open the command prompt under the path of Google Chrome

Open the cmd window under the Google Chrome path

4. Input command

Enter in the cmd window: chrome.exe --remote-debugging-port=9527 --user-data-dir="D:\AutomationProfile" and press Enter.
This code means to start the debug mode of the chrome browser.

  • user-data-dir="D:\AutomationProfile" where D:\AutomationProfile is the path of the newly created folder.
  • Among them, 9527 is the port number, which can be specified by yourself.

If successful, you'll see a new browser window open.

5. Run the code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.common.by import By

options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
driver = webdriver.Chrome(options=options)

url = 'https://www.baidu.com'
driver.get(url)

Guess you like

Origin blog.csdn.net/zhuan_long/article/details/128737459