[英]How to access "Toggle device toolbar" on chrome using Selenium
[英]Open Chrome with Toggle Device Toolbar Activated
我正在 Selenium 中使用 java,我必須自動執行一些測試,一些需要如何使用 Chrome Headless 和 Mobile Emulation。 我知道如何使用“--auto-open-devtools-for-tabs”和“mobileEmulation”打開chrome,但我需要在激活切換設備工具欄的情況下打開它。 這種模式模擬觸摸交互事件,用觸摸代替點擊。 我怎樣才能用這種模式啟動 Chrome? (我正在使用 ChromeDriver v.2.358161)
這是我的代碼:
(...)
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Galaxy S5");
ChromeOptions headlessOptions = new ChromeOptions();
headlessOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, headlessOptions);
driver = new ChromeDriver(capabilities);
(...)
我必須添加什么新論點?
(我讓機器人按Ctrl + shift + M但這不適用於 Chrome Headless)。
protected void pressModoResponsive() throws AWTException {
pressF12();
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
waitSleep(1);
robot.keyPress(KeyEvent.VK_M);
waitSleep(1);
robot.keyRelease(KeyEvent.VK_M);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_CONTROL);
}
我有同樣的問題。 我無法讓 WebDriver 在 selenium 中模擬移動設備。
解決方法是添加參數: --auto-open-devtools-for-tabs
,然后將設備切換到移動設備並使用--user-data-dir
保存會話
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.