appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
376 stars 186 forks source link

Cant seem to tap using new code #712

Closed aaronportier closed 5 months ago

aaronportier commented 7 months ago

I am use to using the Touch Action but now that it has gone away I am trying to use the new way. There are few examples but I am trying using this and I do not see anything happen: Is this the correct way? I have asked in Appium Discussion, Stack Overflow and ChatGPT and all of them do not give anything. Actions actions = new Actions(_IOSdriver); actions.MoveToLocation(23, 315); actions.Click(); actions.Release(); actions.Perform();

Dor-bl commented 7 months ago

Have you checked those examples? https://github.com/appium/dotnet-client/blob/main/test%2Fintegration%2FIOS%2FTouchActionTest.cs

Keep in mind that TouchAction is deprecated and will be removed in future release. From the TouchAction class :

[Obsolete("TouchAction is deprecated, please use W3C actions instead: http://appium.io/docs/en/commands/interactions/actions/")]

aaronportier commented 7 months ago

I want to write them the new way they should be written. The examples you sent me are deprecated. I can't find examples showing how to write a simple tap based on coordinates.

On Mon, Dec 18, 2023, 2:53 PM Dor Blayzer @.***> wrote:

Have you checked those examples?

https://github.com/appium/dotnet-client/blob/main/test%2Fintegration%2FIOS%2FTouchActionTest.cs

Keep in mind that actions are deprecated and will be removed in future release.

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/712#issuecomment-1861471800, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYJVOI7HBMIBZNNWXETYKCNMPAVCNFSM6AAAAABA2AOGA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRRGQ3TCOBQGA . You are receiving this because you authored the thread.Message ID: @.***>

Dor-bl commented 7 months ago

This code is taken from python :

actions = ActionChains(driver)

actions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH, "touch")) actions.w3c_actions.pointer_action.move_to_location(start_x, start_y) actions.w3c_actions.pointer_action.pointer_down() actions.w3c_actions.pointer_action.pause(2) actions.w3c_actions.pointer_action.move_to_location(end_x, end_y) actions.w3c_actions.pointer_action.release() actions.perform()

You can ask GPT to convert it to C# and see if it works

aaronportier commented 7 months ago

This is what I got with ChaptGPT below which does not work however I think what I originally sent you should work it just does not appear to. Hopefully there will be an example with a working solution prior to the touchaction being obsolete.

using OpenQA.Selenium; using OpenQA.Selenium.Interactions;

// Assuming you have an initialized 'driver' object IActionChains actions = new Actions(driver);

// Create a PointerInput for touch interactions PointerInput pointerInput = new PointerInput(Interaction.PointerTouch, "touch");

// Set up the pointer action var moveAction = pointerInput.CreatePointerMove(CoordinateOrigin.Viewport, start_x, start_y, TimeSpan.Zero); var downAction = pointerInput.CreatePointerDown(PointerButton.Left); var pauseAction = pointerInput.CreatePointerPause(TimeSpan.FromSeconds(2)); var moveEndAction = pointerInput.CreatePointerMove(CoordinateOrigin.Viewport, end_x, end_y); var releaseAction = pointerInput.CreatePointerUp(PointerButton.Left);

// Add the actions to the sequence actions.AddAction(moveAction); actions.AddAction(downAction); actions.AddAction(pauseAction); actions.AddAction(moveEndAction); actions.AddAction(releaseAction);

// Perform the actions actions.Perform();

Dor-bl commented 7 months ago

I totally agree, but I didn't had the time to have an example ready, if in the end you are able to get it to work I would appreciate if you could send a PR with the example for our docs or even better a PR with the Unit test.

Dor-bl commented 7 months ago

@aaronportier, I created a short example(Not the cleanest one probably) of how to use the W3C actions : https://gist.github.com/Dor-bl/1b7dde735f4d7f44e320298343dbda18 let me know if you still encounter issues.

aaronportier commented 6 months ago

Thank you for your response. I did have a question some of the touches I have to do are not elements. How would I write them? The below needs an IWebElement Target but I don't have one to give. var move = touch.CreatePointerMove(263, 495, TimeSpan.FromSeconds(1));

On Sat, Dec 23, 2023, 1:13 PM Dor Blayzer @.***> wrote:

@aaronportier https://github.com/aaronportier, I created a short example(Not the cleanest one probably) of how to use the W3C actions : https://gist.github.com/Dor-bl/1b7dde735f4d7f44e320298343dbda18 let me know if you still encounter issues.

— Reply to this email directly, view it on GitHub https://github.com/appium/dotnet-client/issues/712#issuecomment-1868344662, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGVOYIVJ7JQT3E6JHQAGWLYK4NNHAVCNFSM6AAAAABA2AOGA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRYGM2DINRWGI . You are receiving this because you were mentioned.Message ID: @.***>

Dor-bl commented 6 months ago

From what I see CreatePointerMove which is inherited from the Selenium client, and can receive either an element or CoordinateOrigin as a starting point, seems like no way from their end to set an (X, Y) as you seek. Maybe @titusfortner has a suggestion.

eglitise commented 6 months ago

Would something like this work?

var tapPoint = new Point(${x}, ${y});
var move = touch.CreatePointerMove(CoordinateOrigin.Viewport, tapPoint.X, tapPoint.Y, TimeSpan.Zero);
aaronportier commented 6 months ago

@eglitise where is the touch coming from is that using TouchAction? If so we are trying to get rid of that as its not W3C compliant.

Dor-bl commented 6 months ago

@eglitise where is the touch coming from is that using TouchAction? If so we are trying to get rid of that as its not W3C compliant.

This is where the touch is coming from: var touch = new PointerInputDevice(PointerKind.Touch, "finger");

you can take a look at this PR for an example: https://github.com/appium/dotnet-client/pull/721

aaronportier commented 6 months ago

Thanks guys for helping me out and showing me this. If I could can I ask one more question about this? In some tests I use touchAction.LongPress(349, 452).MoveTo(353, 750).Release().Perform(); This is mostly to refresh the page is this in a w3c example I could see?

eglitise commented 6 months ago

It should be the same as a standard coordinate-based swipe, just split the LongPress into CreatePointerDown + CreatePause:

var initialMove = touch.CreatePointerMove(CoordinateOrigin.Viewport, point1.X, point1.Y, TimeSpan.Zero);
var actionPress = touch.CreatePointerDown(PointerButton.TouchContact);
var pause = touch.CreatePause(TimeSpan.FromMilliseconds(800));
var move = touch.CreatePointerMove(CoordinateOrigin.Viewport, point2.X, point2.Y, TimeSpan.Zero);
var actionRelease = touch.CreatePointerUp(PointerButton.TouchContact);

You can then change the pause length to whatever fits your usecase. Alternatively, you can try changing the TimeSpan.Zero in the second CreatePointerMove.

Dor-bl commented 5 months ago

@aaronportier I'm closing this "issue". For further questions please use https://discuss.appium.io/