《SeleniumBasic 3.141.0.0 - 在VBA中操作浏览器》高级技术之五:模拟移动设备
在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
运行程序,会看到: