Selenium禁用弹出窗口"还原页面"- VBA



我在VBA中使用硒ChromeDriver。

  1. 似乎没有一个bot.AddArgument禁用弹出窗口"恢复页面?Chrome没有正确关闭"恢复

  2. 我想用URL打开页面,而不是先打开谷歌搜索页面。我想以编程方式执行此操作(而不是在浏览器设置中手动添加新的"启动时"(。

    Sub VBAChromeDriverBot()
    Dim b As Boolean
    Dim URL  As String
    Dim bot As New ChromeDriver
    bot.SetProfile "%USERPROFILE%DocumentsChromeProfile2"
    bot.AddArgument "url=https://stackoverflow.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://stackoverflow.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%DocumentsChromeProfile2"
Call ReplaceStringInFile
URL = "https://stackoverflow.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") &"DocumentsChromeProfile2Default"
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

最新更新