0

Before Internet Explorer was discontinued, I used this working VBA code to open a website, it was fired via button click in Excel:

Sub OpenWebsiteVBA() 

Dim URL as String
Dim RefString as String
Dim oIE As InternetExplorer 

Set oIE = New InternetExplorer

With oIE
  URL = "https://www.xxxxxxxxxxx.com/index.php?button=Search"
  RefString = "ver_name=All&order_by=2&land_abk=eg&ver_id=3"
  .Navigate2 URL, Headers:="Referer: " & RefString  '<= how to do this with selenium?
End With

End Sub

Microsoft Edge + edgedriver are installed & the Selenium Type Library reference is already added in Excel, but unfortunately I have no advanced knowledge with Selenium and no idea how to integrate the REFERER-code here, so I would be very grateful for support. Which browser doesn't matter, the main thing is that it allows header-post so that I can open the website in it.

Sub OpenWebsiteSELENIUM()

Dim URL As String
Dim RefString As String

Set oEdge = New WebDriver   'or Set oIE = New ChromeDriver

With oEdge
  URL = "https://www.xxxxxxxxxxx.com/index.php?button=Search"
  RefString = "ver_name=All&order_by=2&land_abk=eg&ver_id=3"
  .start "edge"   'or .start "chrome"
  
 '.AddArgument ("Referer:" & RefString)                 <= doesn't work!
 '.SetPreference "Headers: ", "Referer: " & RefString   <= doesn't work!
 '.SetPreference "Referer: ", RefString                 <= doesn't work!
 '.SetPreference "Referer", RefString                   <= doesn't work!
 '.SetPreference "Referer=", RefString                  <= doesn't work!

  .Get URL

End With

End Sub
Jasco
  • 225
  • 3
  • 8
  • This post looks useful. ... https://stackoverflow.com/questions/66551460/vba-selenium-keep-open-edge-browser-after-test?rq=1 – user10186832 Feb 06 '23 at 07:36
  • Thnaks, but I can't find anything about headers there – Jasco Feb 06 '23 at 08:10
  • 1
    Are you sure you need to alter the headers? I don't think that API is included with Selenium VBA, but you could set up a profile with a plugin that alters headers and automate that. See [1](https://chrome.google.com/webstore/detail/modheader-modify-http-hea/idgpnmonknjnojddfkpgkljpfnnfcklj), [2](https://stackoverflow.com/a/41514172/6241235) and [3](https://stackoverflow.com/questions/53351800/how-to-open-chrome-with-extension-using-selenium-vba/53351948#53351948) – QHarr Feb 12 '23 at 16:07
  • 1
    @QHarr: As always: you are the greatest!!! (ModHeader) Thank you very much – Jasco Feb 12 '23 at 23:09

0 Answers0