WebDriver simulate touch events in Desktop Browser

2020-03-27 05:33发布

问题:

I'm trying to simulate some touch events like swap, tap in web-based application using Chrome and Firefox browsers. I've tried to simulate touch events with Actions, Hummber.js, "Yahoo" lib(YUI) but none of them works for me.

What is the best way to simulate touch events with webdriver in desktop browsers?

回答1:

I'm using phantom limb which transforms mouse events to touch events. It worked for me. I thing the best way to simulate touch events in Chrome is to use built-in emulations mechanism. Like in this article. Unfortunately I can't find the way to turn on this feature by webdriver. Found the Chrome options like "enable-touch-events", "touch-events" and etc. But it didn't worked.

UP: Chrome Driver allows to emulate chrome browser on mobile device. Read this article.



回答2:

With jQueryMobile it is quite simple, I execute some Javascript which trigger the corresponding touch events from jQueryMobile.

((JavascriptExecutor)driver).executeScript("window.jQuery('#myId').trigger('swiperight')");

Maybe that helps.