0

this works if I run the below command manually:

google-chrome --remote-debugging-port=9222 --user-data-dir=\"/usr/local/xxx\"'

then I have to open a tab within an existing session manually as well. And than run the Selenium script to get data from manually opened a webpage.

I would like to automate these steps and came up with the below script, but unfortunately it does not work.

is there a way to have a script which opens chrome in debugging mode, then open a new tab, then connect to it with selenium webdriver ?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import webbrowser
import subprocess
from subprocess import call
import os

myCmd = 'google-chrome --remote-debugging-port=9222 --user-data-dir=\"/usr/local/xxx/Project\"'
print (myCmd)

subprocess.call(myCmd,shell=True)



chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
#Change chrome driver path accordingly
driver = webdriver.Chrome('/usr/local/xxx/chromedriver')  # Optional argument, if not specified will search path.
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)




webbrowser.open('https://www.seleniumhq.org')


# print driver.title
greenszpila
  • 193
  • 1
  • 1
  • 14
  • [This](https://stackoverflow.com/a/53599599/3091398) should help you. When specifying a path make sure your pass absolute path. – CodeIt Oct 24 '19 at 15:25
  • thanks, but the problem is that the script stop executing lines of code after the subprocess.call runs the 'google-chrome --remote-debugging-port=9222 --user-data-dir=\"/usr/local/xxx/Project\"' , do you know how to get around this problem? – greenszpila Oct 25 '19 at 08:30
  • You are trying to attach a regular chrome browser to selenium driver. Take a look at this [repo](https://github.com/fate0/pychrome). – CodeIt Oct 25 '19 at 14:19

0 Answers0