To generate a tap (touch) event on the Selenium ChromeDriver

Asked 2 years ago, Updated 2 years ago, 141 views

Tap event for specific elements in ChromeDriver
touchstart
touchend
How do I code to trigger the?

c# selenium selenium-webdriver chromedriver

2022-09-30 18:13

2 Answers

I've never used it, so I guess it's from the search results.
You will use the following:Check these out and try them.

Get Touch Screen Interface
serenium/dotnet/src/webdriver/IHasTouchScreen.cs
serenium/dotnet/src/webdriver/Interactions/TouchAction.cs
If present, the object will return, otherwise null or an exception will occur.

touchstart, touchend.
serenium/dotnet/src/webdriver/ITouchScreen.cs
serenium/dotnet/src/webdriver/Interactions/TouchActions.cs
The following Down(locationX,locationY); corresponds to touchstart, Up(locationX,locationY); corresponds to touchend.

//<summary>
/// Allow the execution of the gesture 'down' on the screen. It is the first of a
/// sequence of touch gestures.
/// </summary>
/// <param name="locationX">The x coordinate relative to the view port.</param>
/// <param name="locationY">The y coordinate relative to the view port.</param>
void Down (int locationX, int locationY);

/// <summary>
/// Allow the execution of the gesture 'up' on the screen. It is the last of a
/// sequence of touch gestures.
/// </summary>
/// <param name="locationX">The x coordinate relative to the view port.</param>
/// <param name="locationY">The y coordinate relative to the view port.</param>
void Up (int locationX, int locationY);

In order to obtain the x,y position of a particular element, isn't it possible to follow the steps below?
And if it's outside the actual display range, like this article, you'll need to scroll and bring it to the screen.
Selenium ChromeDriver how to click elements with negative x,y pixel locations?C#

// Must close unless the popup may (or may not) cover the next link.
varcloseButton=Session.Driver.FindElement(By.Id(id))
    .FindElements(By.CssSelector("a.cmg_close_button"))
    .FirstOrDefault();
if(closeButton!=null)
{
    Wait.Until(d=>closeButton.Displayed);

    if (closeButton.Location.Y<0||closeButton.Location.X<0)
    {
        Log.Error("Could not close button.The popup displayed the close_button off-screen giving it a negative x or y pixel location.");
    }
    else
    {
        closeButton.Click();
    }
}


2022-09-30 18:13

Specific implementation examples are
webdriver with Touch events

The link is for iOS and Android, but
Chrome on Windows will work the same way.

A simple touch event has occurred, so I will link the code.

var options=new ChromeOptions();
options.EnableMobileEmulation("Nexus6P");//Allows the Chrome browser to emulate a mobile device.
_driver = new ChromeDriver(options);
_driver.Url = "Desired URL";
IWebElement testDiv=_driver.FindElement(By.Id("testDiv"));
testDiv.Click();

Launch Chrome in mobile device emulation mode and click events
It's just happening.
The touchstart and touchend events have now occurred.
However, touchmove does not occur.

Using TouchActions as shown below seems to work with Appium for remote devices, but it did not work with Chrome on Windows.
※ The code https://stackoverflow.com/a/49135541

that I referenced at that time
new OpenQA.Selenium.Interactions.TouchActions (driver)
.Down(x,y).Move(150,0).Perform();

I haven't found out how to launch a touch event in Chrome on Windows yet.

http://appium.io/

using the remote control method of apps on Windows instead of browser control. The touch event may be processed a little more, but it has not been confirmed yet.


2022-09-30 18:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.