Tuesday, May 16, 2023

HOW TO GET chromeSessionId 2023

 To get the `chromeSessionId` of an open Chrome window, you need to use the Chrome DevTools Protocol. Here are the steps:


1. Open a new tab in the open Chrome window.

2. Enter the following URL in the address bar: `chrome://version/`.

3. Look for the `Remote debugging port` field and note down the value. For example, the value could be `9222`.

4. Open a command prompt or terminal and run the following command: `curl http://localhost:9222/json`.

5. The output of the command will be a JSON array of all the open tabs and their respective `devtoolsFrontendUrl` and `id` values. Find the tab that you want to attach to and note down its `id` value. For example, the `id` value could be `"page_1"`.

6. Use the `id` value to create the `chromeSessionId` string in the following format: `chrome --remote-debugging-port=9222 --user-data-dir="C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data" --disable-web-security --no-first-run --no-default-browser-check --no-check-default-browser --silent --new-window --remote-debugging-pipe --page-id=page_1`.

7. Replace the `page_1` value with the actual `id` value you obtained in step 5.

8. Run the `chromeSessionId` command in a new command prompt or terminal window. This will launch a new Chrome window with the tab you want to attach to.

9. Use the `chromeSessionId` value in your Selenium script to attach to the open Chrome window, as shown in the previous answers.

0 comments:

Post a Comment