0

I'm coding in VBA. Is there a way to refer to an existing, open Chrome window using Selenium ChromeDriver?

Every time I open a new Chrome window, using Set x as New Selenium.ChromeDriver then navigate using x.Get URL, but this always opens up a new window.

Is there a way to refer to a Chrome window which is already open, and use that window in my code? I'm looking for something similar to:

Set Shell = New Shell32.Shell
For Each IE In Shell.Windows
    If InStr(1, IE.LocationURL, strSearchURL) <> 0 Then Set IEFound = IE 'Heureka!
Next IE

UPDATE:

Someone linked this question with another one. The linked question is not the same -- not even close. It asks for some way of restarting the session without closing and reopening the browser, in order to gain performance. My problem is the opposite: how to attach an open instance of Chrome (the same, not restarted) to a new Driver object, in another procedure.

In the second answer, someone give a hint which might work, using webdriver.session_id. unhappily, ChromeDriver for VBA doesn't have this attribute.

According to this (https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/18), it's not feasible. Snif.

César Rodriguez
  • 296
  • 5
  • 16
  • See `GetObject`. –  Jan 29 '20 at 06:47
  • Unfortunately, I think ```GetObject``` doesn't work, because it wouldn't let me use the same Chrome window with webdriver. According to the specification (https://learn.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/getobject-function), it would open a new instance. :-/ – César Rodriguez Jan 29 '20 at 20:54
  • Scroll down that page and read _ Note Use the `GetObject` function **when there is a current instance** of the object or if you want to create the object with a file already loaded. If there is no current instance, and you don't want the object started with a file loaded, use the `CreateObject` function._ –  Jan 29 '20 at 21:17
  • That must be the worst documentation on `GetObject` I've seen. Here it is summarised **Execute the file so it opens like a user would and use `GetObject` on it. You need to read help on `GetObject` as it is overloaded. `GetObject(Filename)` switches to filename or opens if not already open returning a `document` object. `GetObject(,"Internet.Explorer")` note , we are setting the SECOND parameter - Switches to an already running application only, returning an `Application` Object. The third that I not seen anyone do is `GetObject(FileName, Application.Name)` open doc in app. –  Jan 29 '20 at 21:20

0 Answers0