• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to open chrome window and capture the same window with the specified url.

Sarvesh1993

New Member
Hi Guys,

There is a business requirement where I have to open a browser with the URL and capture the same window .I got the code for Internet Explorer and its working fine in IE but they told to do same thing in chrome/Edge . The below code is opening the window with URL and capture the window with a target URL. Could you help with the Exact code ,how can I achieve similar thing in Edge/Chrome


Code:
Sub OpenIE(MyURL As String)
Dim objIEBrowser

Set objIEBrowser = CreateObject("InternetExplorer.Application")

objIEBrowser.Visible = True
objIEBrowser.Navigate2 MyURL

End Sub



Code:
Public Function FindIEObject(target As String)
Dim objShell
Dim IE_count
Dim X
Dim IEWindow
Dim my_url
Dim my_title


    Set objShell = CreateObject("Shell.Application")
    IE_count = objShell.Windows.Count
    For X = 0 To (IE_count - 1)
        On Error Resume Next    ' sometimes more web pages are counted than are open
        my_url = objShell.Windows(X).document.Location
        my_title = objShell.Windows(X).document.Title
        If my_url = target Then 'compare to find if the desired web page is already open
            Set FindIEObject = objShell.Windows(X)
       Exit For
       Else
       Set FindIEObject = Nothing
        End If
    Next
End Function
 
Hi,​
see if exists any documentation for chrome, better to ask on a chrome forum …​
You can try some add-in like you can find out on the chrome store or like selenium (in this case see on a specific selenium forum) …​
 
Hi Sir,

Opening the url in different browser is not a challenge but getting that window which is opened ,I gone through those links ,could not get the exact thing ,how can I capture the same window open ,could you help me on the same How can I capture the same window open using shell command/Selenium


Code:
Sub OpenURL(ByVal sURL As String, ByVal lBrowser As BrowserName)
    On Error GoTo Error_Handler
    Dim WSHShell              As Object
    Dim sFFExe                As String     'Executable path/filename
    Dim sProgName             As String     'Name of the Executable program
    Dim sExe                  As String     'Excutable exe filename
    Dim sCmdLineSwitch        As String     'Command line switch
    Dim sShellCmd             As String     'Shell Command
 
    'Determine the Path to FF executable
    Select Case lBrowser
        Case 1
            'https://msdn.microsoft.com/en-us/library/hh826025(v=vs.85).aspx
            sProgName = "Internet Explorer"
            sExe = "IEXPLORE.EXE"
            sCmdLineSwitch = " "
        Case 2
            'https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#Browser
            sProgName = "Mozilla Firefox"
            sExe = "Firefox.EXE"
            sCmdLineSwitch = " -new-tab "
        Case 3
            sProgName = "Google Chrome"
            sExe = "Chrome.exe"
            sCmdLineSwitch = " -tab "
        Case 4
            'http://www.opera.com/docs/switches/
            sProgName = "Opera"
            sExe = "opera.exe"
            sCmdLineSwitch = " "
    End Select
    Set WSHShell = CreateObject("WScript.Shell")
    sFFExe = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" & _
                              "CurrentVersion\App Paths\" & sExe & "\")
    sFFExe = Replace(sFFExe, Chr(34), "")    'Special case for Opera?!
    'Open the URL
    sShellCmd = """" & sFFExe & """" & "" & sCmdLineSwitch & """" & sURL & """"
    Shell sShellCmd, vbHide
 
Error_Handler_Exit:
    On Error Resume Next
    If Not WSHShell Is Nothing Then Set WSHShell = Nothing
    Exit Sub
 
Error_Handler:
    If Err.Number = -2147024894 Then
        MsgBox sProgName & " does not appear to be installed on this compter", _
               vbInformation Or vbOKOnly, "Unable to open the requested URL"
    Else
        MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: OpenURL" & vbCrLf & _
               "Error Description: " & Err.Description & _
               Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
               , vbOKOnly + vbCritical, "An Error has Occurred!"
    End If
    Resume Error_Handler_Exit
End Sub
 
So read up on Selenium ;) And ask in their forum as Marc suggested.
I'm not a fan of Selenium and don't use it.

Or use FindWindow, GetActiveWindow, EnumWindows function(s) etc from WinAPI to work with multiple chrome window.
 
Sir,

I was trying another approach, since to use selenium ,we need to install selenium web driver into machine and we cant install selenium in each client machine ,so I have added a ActiveX Microsoft web browser control into Excel and I can see the page being loaded ,now I want to read the session value from the document when the page is loaded into my web browser control , from microsoft website I got to know ,we can access the document property ,need help with the code for that ,any advice ?
 
Back
Top