Selenium 禁用弹出窗口 'Restore page'- VBA

Selenium disable popup 'Restore page'- VBA

我在 VBA.

中使用 selenium Chrome驱动程序
  1. None 的 bot.AddArgument 似乎禁用了弹出窗口“恢复页面? Chrome 没有正确关闭。” restore

  2. 我想用 URL 打开页面而不是先打开 Google 搜索 page.I 想以编程方式执行此操作(而不是手动添加新的 'On startup' 在浏览器设置中)。

    Sub VBAChromeDriverBot()
    Dim b As Boolean
    Dim URL  As String
    Dim bot As New ChromeDriver
    bot.SetProfile "%USERPROFILE%\Documents\ChromeProfile2"
    bot.AddArgument "url=https://whosebug.com/"
    bot.AddArgument "--disable-extensions"
    bot.AddArgument "--disable-session-crashed-bubble"
    bot.AddArgument "--disable-application-cache"
    bot.AddArgument "--disable-popup-blocking"
    bot.AddArgument "--disable-notifications"
    bot.AddArgument "--test-type"
    
    URL = "https://whosebug.com/"
    bot.Get URL
    If b = False Then bot.Window.Maximize: b = True
    Stop
    bot.Quit
    End Sub
    

在 VBA 中实施 QHarr 建议:

Sub VBAChromeDriverBot()
Dim b As Boolean
Dim URL  As String
Dim bot As New ChromeDriver
bot.SetProfile "%USERPROFILE%\Documents\ChromeProfile2"
Call ReplaceStringInFile
URL = "https://whosebug.com/"
bot.Get URL
If b = False Then bot.Window.Maximize: b = True
Stop
bot.Quit
End Sub

Sub ReplaceStringInFile()
Const ForReading = 1
Const ForWriting = 2
Dim objFSO
Dim objTS 'define a TextStream object
Dim strContents As String
Dim folderpath As String
Dim FileName As String
Dim FileNamefound As String

folderpath = Environ$("USERPROFILE") &"\Documents\ChromeProfile2\Default\"
FileName = "Preferences"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(folderpath & FileName, ForReading)
strContents = objTS.ReadAll
strContents = Replace(strContents, "Crashed", "none")
objTS.Close
Set objTS = objFSO.OpenTextFile(folderpath & FileName, ForWriting)
objTS.Write strContents
objTS.Close
End Sub