在Chrome瀏覽器中按下F12,彈出開發工具,右側有個設置按鈕,點擊一下。
左側選擇“Devices”,右側看到可以模擬的設備列表,例如IPhone X
確認完以后,在VBA中設置Chrome選項。
Private WD As SeleniumBasic.IWebDriver Sub Baidu() On Error GoTo Err1 Dim Service As SeleniumBasic.ChromeDriverService Dim Options As SeleniumBasic.ChromeOptions Set WD = New SeleniumBasic.IWebDriver Set Service = New SeleniumBasic.ChromeDriverService With Service .CreateDefaultService driverPath:="E:\Selenium\Drivers" .HideCommandPromptWindow = True End With Set Options = New SeleniumBasic.ChromeOptions With Options .BinaryLocation = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" .EnableMobileEmulation deviceName:="iPhone X" End With WD.New_ChromeDriver Service:=Service, Options:=Options WD.URL = "https://www.cnblogs.com/ryueifu-VBA/p/13698908.html" End Sub
運行程序,會看到: