microsoft / WinAppDriver

Windows Application Driver
MIT License
3.65k stars 1.4k forks source link

Scrolling in winappdriver #1538

Open krevathi1912 opened 3 years ago

krevathi1912 commented 3 years ago

I am automating UWP app using appium+winappdriver Winappdirver version - 1.2 RC

Our app has a page, where certain elements will be loaded only on scrolling down the page. There is a vertical scroll bar element, but it is getting enabled only when mouse cursor is moved over it. Please let me know how to handle scrolling in this case. I am using python language

image

anunay1 commented 3 years ago

WAD supports auto scroll max till 40 elements. What is been shown in inspect for the vertical scroll bar.

krevathi1912 commented 3 years ago

@anunay1 WAD scrolls when the element is available(shown on inspecting) though it is not in the view, whereas the element that i want is drawn only when the page is scrolled down(it is shown on inspect only when page is scrolled down). In the inspect the vertical scroll bar element is shown, but is not available for interactions, when the mouse is moved over the vertical scroll bar, it loads other elements inside the vertical scroll bar

image

image

anunay1 commented 3 years ago

can you try this:

ele= driver.find_element_by_name('last element in your list') ele.send_keys(Keys.PAGE_DOWN)

or else:

ele= driver.find_element_by_name('last element in your list') ele.click() ele.send_keys(Keys.PAGE_DOWN)

shoaibmansoor commented 3 years ago

Hi @krevathi1912 If I am not mistaken, Winappdriver supports scrolling by Touch API. You may refer to examples provided by the team: image

link

I would suggest checking flick api as well.

From python, you can import TouchActions by the following line: from selenium.webdriver import TouchActions

krevathi1912 commented 3 years ago

@shoaibmansoor
I tried touch actions, it not working, shows 500 server error, i think it requires touch screen and my desktop where tests are running doesn't have touch screen. Touch actions require touch screen in the device, Correct me if i am wrong

shoaibmansoor commented 3 years ago

@krevathi1912 Windows 10 or servers are touch-enabled as far as I know. It looks like some configuration issue at your end. I just tested and it works perfectly fine: image

Are you using something similar? TouchActions(driver).scroll(0, 100).perform()

anunay1 commented 3 years ago

@krevathi1912 is it a UWP application or WPF

krevathi1912 commented 3 years ago

@anunay1 its UWP application developed using xamarin technology

anunay1 commented 3 years ago

Did you try the page down thing

anunay1 commented 3 years ago

Did you try hovering the mouse over the vertical scroll bar?

krevathi1912 commented 3 years ago

Did you try the page down thing

Yes, Keys.PAGE_DOWN is working. Thank you very much

krevathi1912 commented 3 years ago

Did you try hovering the mouse over the vertical scroll bar?

I am not sure how to achieve this, request your help.

krevathi1912 commented 3 years ago

@shoaibmansoor Scroll is working now after i use the touch action module in selenium(from selenium.webdriver import TouchActions). Earlier i was using TouchAction class of touch_action module in appium (from appium.webdriver.common.touch_action import TouchAction) which throwed error. Thank you very much for your response

krevathi1912 commented 3 years ago

@shoaibmansoor TouchActions(driver).scroll(0, 100).perform() makes a small scroll, how to scroll till the end of the page till the element is found. Request your help

anunay1 commented 3 years ago

change the value to 200 and use a while loop to check if the element is displayed, break and then click the element.

krevathi1912 commented 3 years ago

@anunay1 When the element is not visible it throws no such element exception and not returning False value, used driver.find_element_by_accessibility_id("value").is_displayed() method

krevathi1912 commented 3 years ago

@anunay1 @shoaibmansoor Appreciate you help, facing below issue

When the element is not visible it throws no such element exception and not returning False value, used driver.find_element_by_accessibility_id("value").is_displayed() method

anunay1 commented 3 years ago

You can do the below: i = 0 while i == 100: TouchActions(driver).scroll(0, 100).perform(); try: if(driver.find_element_by_accessibility_id("value").is_displayed()) break; except NoSuchElement: i++

krevathi1912 commented 3 years ago

@anunay1 I can see the code tries scrolling for first time, but the page stands there by and not moved up, also from second time, no scroll happening. Request your help

anunay1 commented 3 years ago

Unfortunately I do not have any application like that to test, please ping me at anunayathakur1@gmail.com we can have a hangout all.

krevathi1912 commented 3 years ago

@anunay1 TouchActions(driver).scroll(0, 100).perform(); code is scrolling down after giving y offset in negative TouchActions(driver).scroll(0, -100).perform();

Thank you very much

uqix commented 2 years ago

TouchActions(driver).scroll(0, -100).perform();

results in:

java.lang.ClassCastException: class io.appium.java_client.windows.WindowsDriver cannot be cast to class org.openqa.selenium.interactions.HasTouchScreen (io.appium.java_client.windows.WindowsDriver and org.openqa.selenium.interactions.HasTouchScreen are in unnamed module of loader 'app')

huster-songtao commented 2 years ago

can you try this:

ele= driver.find_element_by_name('last element in your list') ele.send_keys(Keys.PAGE_DOWN)

or else:

ele= driver.find_element_by_name('last element in your list') ele.click() ele.send_keys(Keys.PAGE_DOWN)

ele.SendKeys(Keys.PageUp); An unknown error occurred in the remote end while processing the command.

huster-songtao commented 2 years ago

https://github.com/GregsStack/InputSimulatorStandard This library is a fork of Michael Noonan's Windows Input Simulator and Theodoros Chatzigiannakis's Input Simulator Plus (a C# wrapper around the SendInput functionality of Windows). It can be used as a replacement of the original library with some small source code changes.

This fork supports scan codes, making it compatible with many applications that the original library does not support.

The target framework has been changed to .Net Standard to support the usage with .Net Core and .Net Framework projects on Windows.

Simulates mouse vertical wheel scroll gesture. Scroll up to target element.

https://github.com/michaelnoonan/inputsimulator/issues/14#issuecomment-350210711

// you need to move your mouse pointer to a scrollable area first. For ex: if there is a element with scrollbars, you need to move your mouse pointer over element before trying to perform a scroll. If the scrollable content has no focus, it will not work.
// element is a scrollable area

                while(target.GetAttribute("IsOffscreen") == "True")
                {
                    session.SwitchTo();
                    Actions actions = new(session);
                    actions.MoveToElement(element, Convert.ToInt32(element.Size.Width / 2), Convert.ToInt32(element.Size.Height / 2)).Perform();
                    // 4 The amount to scroll in clicks.
                    // A positive value indicates that the wheel was rotated forward, away from the user; 
                    // a negative value indicates that the wheel was rotated backward, toward the user.
                    simulator.Mouse.VerticalScroll(4); // -600;
                    Thread.Sleep(50);
                }

It work well.

If you want to use target.SendKeys(Keys.PageUp); to replace simulator.Mouse.VerticalScroll(4);, you must focus the target element first. If the scrollable content has no focus, it will not work.

LisaAga commented 2 years ago

@krevathi1912 : Can you help me here which package you are using to import TouchActions?

LisaAga commented 2 years ago

@anunay1 Even i am getting this error java.lang.ClassCastException: class io.appium.java_client.windows.WindowsDriver cannot be cast to class org.openqa.selenium.interactions.HasTouchScreen (io.appium.java_client.windows.WindowsDriver and org.openqa.selenium.interactions.HasTouchScreen are in unnamed module of loader 'app')

LisaAga commented 2 years ago

unnamed module of loader 'app')

@anunay1 TouchActions(driver).scroll(0, 100).perform(); code is scrolling down after giving y offset in negative TouchActions(driver).scroll(0, -100).perform();

Thank you very much

what is your driver here ? is it a windowsdriver?or a webdriver?

DavitD1996 commented 1 year ago

Hello dear community.@krevathi1912 I try to automate the windows desktop app by using winappdriver and java and now I receive this error when try to instate the TouchActions class' instance java.lang.ClassCastException: class io.appium.java_client.windows.WindowsDriver cannot be cast to class org.openqa.selenium.interactions.HasTouchScreen (io.appium.java_client.windows.WindowsDriver and org.openqa.selenium.interactions.HasTouchScreen are in unnamed module of loader 'app')

I have imported in my maven the following dependencies maybe the problem is here who can clarify

org.seleniumhq.selenium selenium-java 3.141.59
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.6.0</version>
        </dependency>
cqm0609 commented 5 months ago

I've tried all of the above, but none of them can solve the problem.After my research, I solved the problem. from selenium.webdriver import ActionChains vertical_scrollbar = driver.find_element(By.XPATH,"//ScrollBar[@AutomationId=\"2538\"]") if vertical_scrollbar is not None: action_chain.drag_and_drop_by_offset(vertical_scrollbar, 0, 600).release().perform()

chilakamarthi commented 2 weeks ago

For Appium WinAppDriver I tried this and it works

` bool act = true; try { if (driver.FindElementByAccessibilityId("NonClientVerticalScrollBar").Displayed) { switch (moveDirection) { case MoveDirection.Up: while (act) { if (int.Parse(driver.FindElementByAccessibilityId("NonClientVerticalScrollBar").GetAttribute("LegacyValue")) < minValue) { driver.FindElementByName("Menu_LibGallery").FindElementByAccessibilityId("NonClientVerticalScrollBar").FindElementByAccessibilityId("UpPageButton").Click(); Logger.Logger.LogInfo("Clicked on PageUp button"); } else { act = false; } } break; case MoveDirection.Down: while (act) { if (int.Parse(driver.FindElementByAccessibilityId("NonClientVerticalScrollBar").GetAttribute("LegacyValue")) < 100) { driver.FindElementByName("Menu_LibGallery").FindElementByAccessibilityId("NonClientVerticalScrollBar").FindElementByAccessibilityId("DownPageButton").Click(); Logger.Logger.LogInfo("Clicked on PageDown button"); } else { act = false; } } break; case MoveDirection.Left: case MoveDirection.Right: default: break; } }

        }
        catch (Exception)
        {
            Logger.LogInfo("Scrollbar is not shown, nothing to do...");
            return;
        }

`