florentbr / SeleniumBasic

A Selenium based browser automation framework for VB.Net, VBA and VBScript
BSD 3-Clause "New" or "Revised" License
421 stars 197 forks source link

Open Chrome with an exsisting profile, when same profile is already open #275

Closed Shumatic closed 10 months ago

Shumatic commented 10 months ago

Hi

Thanks for this Wrapper:-) I am trying to open a new instance of chrome with my default profile, with chrome open, like this

Dim driver As New Selenium.ChromeDriver
Sub test()
driver.SetProfile "C:\Users\xxx\AppData\Local\Google\Chrome\User Data"
driver.AddArgument ("user-data-dir=C:\Users\xxx\AppData\Local\Google\Chrome\User Data")
driver.start "chrome", ""
End Sub

and i get this error.

is there a workaroun for this? I read i should use an other profile, but i need my default one, and copying it isn't a solution as it is 4Gb

image

is there a workaroun for this? I read i should copy my profile and use that, but i need my default one, and copying it isn't a solution as it is 4Gb

TeaSast3r commented 10 months ago

You can try this: Replace: driver.SetProfile "C:\Users\xxx\AppData\Local\Google\Chrome\User Data" driver.AddArgument ("user-data-dir=C:\Users\xxx\AppData\Local\Google\Chrome\User Data")

With: driver.AddArgument "profile-directory=Profile 1" driver.AddArgument "--user-data-dir=C:\Users\272763\AppData\Local\Google\Chrome\User Data\"

BUT: In the "driver.AddArgument "profile-directory=Profile 1"" replace "Profile 1" with your profile. To find this open the webpage "chrome://version/" while logged-in to the profile you want to open with VBA. You should the see something like "C:\Users\teasaster\AppData\Local\Google\Chrome\User Data\Profile 1". Copy the last part and replace "Profile 1" in driver.AddArgument "profile-directory=Profile 1"

To give you a complete picture, this is the part of the code I used to enter to a website with my profile:

Dim driver As New ChromeDriver driver.AddArgument "profile-directory=Profile 1" driver.AddArgument "--user-data-dir=C:\Users\272763\AppData\Local\Google\Chrome\User Data\" driver.Start driver.Window.Maximize driver.Get "https://www.mywebsite.com"

Shumatic commented 10 months ago

Thanks looks like this do the trix:-)

rufogil commented 8 months ago

You can try this: Replace: driver.SetProfile "C:\Users\xxx\AppData\Local\Google\Chrome\User Data" driver.AddArgument ("user-data-dir=C:\Users\xxx\AppData\Local\Google\Chrome\User Data")

With: driver.AddArgument "profile-directory=Profile 1" driver.AddArgument "--user-data-dir=C:\Users\272763\AppData\Local\Google\Chrome\User Data"

BUT: In the "driver.AddArgument "profile-directory=Profile 1"" replace "Profile 1" with your profile. To find this open the webpage "chrome://version/" while logged-in to the profile you want to open with VBA. You should the see something like "C:\Users\teasaster\AppData\Local\Google\Chrome\User Data\Profile 1". Copy the last part and replace "Profile 1" in driver.AddArgument "profile-directory=Profile 1"

To give you a complete picture, this is the part of the code I used to enter to a website with my profile:

Dim driver As New ChromeDriver driver.AddArgument "profile-directory=Profile 1" driver.AddArgument "--user-data-dir=C:\Users\272763\AppData\Local\Google\Chrome\User Data" driver.Start driver.Window.Maximize driver.Get "https://www.mywebsite.com/"

Hi there, I'm getting the following error "Run-time error '33: SessionNotCreatedError session not created: Chrome failed to start: exited normally, (session not created: DevToolsActivePort file doesn't exist) The process started from chrome location C: program Files.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed. (Driver info: chromedriver=120.0.6099.109"), in the line driver.Start I copied and pasted your code and just changed the profile-directory and the user-data-dir with my user folders. However, it is not crashing as the error is assuming since I can see the Chrome windows popping up with my user in it. Any ideas what is wrong? Thanks!

gauravsingh06 commented 1 week ago

you need to close every running process of chrome to make it work!