Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Python Selenium Chrome webdriver remote with Current user data?

  1. How I create LOCAL Chrome Webdriver WITH Current user data

    chromedriver = "/Users....../chromedriver"
    os.environ["webdriver.chrome.driver"] = chromedriver
    options = webdriver.ChromeOptions()
    options.add_argument(r"user-data-dir=/Users..../Google/Chrome")
    webdriver.Chrome(executable_path=chromedriver,
                          chrome_options=options)
    
  2. How I create REMOTE Chrome webdriver with clear - new user data

    webdriver.Remote(command_executor="http://192.168.1.30:4441/wd/hub",
                desired_capabilities=DesiredCapabilities.CHROME)
    

Now, How create Remote Chrome webdriver with current user data?

like image 751
Станислав Повышев Avatar asked Jun 22 '15 18:06

Станислав Повышев


People also ask

How do I use an existing Chrome profile in Selenium Python?

We can use a specific Chrome profile in Selenium. This can be done with the help of the ChromeOptions class. We need to create an object of this class and then apply addArguments method on it. The path of the specific Chrome profile that we want to use is passed as a parameter to this method.

How do I use an existing Chrome profile in Selenium?

We can open Chrome default profile with Selenium. To get the Chrome profile path, we need to input chrome://version/ in the Chrome browser and then press enter. We need to use the ChromeOptions class to open the default Chrome profile. We need to use the add_argument method to specify the path of the Chrome profile.

Can Selenium interact with an existing browser session?

We can interact with an existing browser session. This is performed by using the Capabilities and ChromeOptions classes. The Capabilities class obtains the browser capabilities with the help of the getCapabilities method.


1 Answers

Try this:

os.environ["webdriver.chrome.driver"] = chromedriver
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/Users..../Google/Chrome")
webdriver.Remote("http://192.168.1.30:4441/wd/hub",
        options.to_capabilities())

And if you have your chromedriver.exe on the PATH then you should not need this part:

chromedriver = "/Users....../chromedriver"

Not sure if that works for you, but here is an example that let me start remote chrome webdriver with desired chromeOption for language:

options = webdriver.ChromeOptions()
options.add_argument("--lang=de")
chrome_remote = webdriver.Remote('http://hostname:4444/wd/hub', options.to_capabilities())
like image 183
Wlad Avatar answered Nov 01 '22 10:11

Wlad