Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling in winappdriver #1538

Open
krevathi1912 opened this issue Jun 5, 2021 · 29 comments
Open

Scrolling in winappdriver #1538

krevathi1912 opened this issue Jun 5, 2021 · 29 comments

Comments

@krevathi1912
Copy link

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
Copy link

anunay1 commented Jun 7, 2021

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

@krevathi1912
Copy link
Author

krevathi1912 commented Jun 7, 2021

@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
Copy link

anunay1 commented Jun 7, 2021

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
Copy link

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
Copy link
Author

@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
Copy link

@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
Copy link

anunay1 commented Jun 7, 2021

@krevathi1912 is it a UWP application or WPF

@krevathi1912
Copy link
Author

@anunay1 its UWP application developed using xamarin technology

@anunay1
Copy link

anunay1 commented Jun 7, 2021

Did you try the page down thing

@anunay1
Copy link

anunay1 commented Jun 7, 2021

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

@krevathi1912
Copy link
Author

Did you try the page down thing

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

@krevathi1912
Copy link
Author

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

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

@krevathi1912
Copy link
Author

krevathi1912 commented Jun 7, 2021

@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
Copy link
Author

@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
Copy link

anunay1 commented Jun 7, 2021

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

@krevathi1912
Copy link
Author

@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
Copy link
Author

@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
Copy link

anunay1 commented Jun 8, 2021

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
Copy link
Author

@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
Copy link

anunay1 commented Jun 11, 2021

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
Copy link
Author

@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
Copy link

uqix commented Nov 4, 2021

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
Copy link

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
Copy link

huster-songtao commented Dec 17, 2021

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.

michaelnoonan/inputsimulator#14 (comment)

// 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
Copy link

LisaAga commented Jul 27, 2022

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

@LisaAga
Copy link

LisaAga commented Jul 27, 2022

@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
Copy link

LisaAga commented Jul 27, 2022

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
Copy link

DavitD1996 commented May 7, 2023

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


io.appium
java-client
7.6.0

@cqm0609
Copy link

cqm0609 commented Apr 10, 2024

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants