I am automating desktop application where i have list box in which many items are listed and i want to click on the item which is hidden and that item will shows after scrolling the list. Which code will work for this? I am working with WinAppdriver, appium , c# and MSTest. I need such lines of code with which list will scroll till the element finds.
2 Answers
Someone guide me this solution and it is working for me now. So, i am posting answer here.
The List Box has accessibility item "lbStates". We want to click the item "NC" in it which has the text "NC". In this case the "Displayed" property of most of the list items will be false. We can click the down button in the ListBox to scroll down or We can press the keys buttons and test if the value which we want to click is displayed or not. It is possible that the value we want to click is not present in the listbox, in such case our code will go in a deadlock and for that purpose I've introduced the integer maxClicks.
[TestMethod]
public void ListBoxTest()
{
//lbStates
var lbStates = sessionWinForm.FindElementByAccessibilityId("lbStates");
var allListItems = lbStates.FindElementsByTagName("ListItem");
var valueToClick = "NC";
var maxClicks = 10;
foreach(var ali in allListItems)
{
Debug.WriteLine($"{ali.Displayed} - {ali.Text}");
if(ali.Text.Equals(valueToClick) && !ali.Displayed)
{
var downButton = lbStates.FindElementByAccessibilityId("DownButton");
var listItemToClick = lbStates.FindElementByName(valueToClick);
while(!listItemToClick.Displayed && (maxClicks-- > 0))
{
downButton.Click();
listItemToClick = lbStates.FindElementByName(valueToClick);
if (listItemToClick.Displayed)
{
listItemToClick.Click();
}
}
}
}
}

- 152
- 1
- 12
you can just find your element with winappdriver and it will scroll itself to the element , i have automated a windows application with had a input box that accept a file and had a browser button after clicking browse button it itself scroll till the element is found.
Regarding the code you may just try finding the element normal like it is in view .
Hope this helps. :)

- 66
- 4
-
I tried this earlier but it is showing that no element find. – Neh18 Feb 13 '20 at 09:00
-
Can you please share your code and also verify that your driver control is on this window . – Sukhangad singh Feb 13 '20 at 09:12
-
Yes my control is on windows because if i click on visible element then it is clicking on it and when i define hidden elements then it is not clickable. – Neh18 Feb 14 '20 at 04:33
-
var currentWindowHandle3 = driver.CurrentWindowHandle; Thread.Sleep(TimeSpan.FromSeconds(3)); var allWindowHandles3 = driver.WindowHandles; driver.SwitchTo().Window(allWindowHandles3[0]); Thread.Sleep(1000); WindowsElement visibletext = driver.FindElementByName("xxxxxxxxxxxxxxx"); Actions action= new Actions(driver); action.MoveToElement(visibletext).Click().Build().Perform(); driver.FindElementByAccessibilityId("OkButton").Click(); – Neh18 Feb 14 '20 at 04:33
-
Your answer is right in those cases where all the list item is loaded in the list. In my case i have to scroll the list only then all the list will be loaded. So i have tried below answer which is working for me now. – Neh18 Feb 14 '20 at 09:37
-
Oh, i see. There is one more way to scroll down , using RemoteTouchScreen class , code : RemoteTouchScreen rem = new RemoteTouchScreen(new RemoteExecuteMethod((RemoteWebDriver) this.driver)); rem.scroll(0, -100); //down rem.flick(0, -100); //up – Sukhangad singh Feb 15 '20 at 15:52
-
It is showing error on RemoteExecuteMethod(The Type or namespace RemoteExecuteMethod could not be found (may be missing any reference or directives)) and i have imported **using OpenQA.Selenium.Remote;** and I guess this case is valid in Web app(Because you mentioned RemoteWebDriver). I am working on Windows application. – Neh18 Feb 17 '20 at 05:44
-
i have automated a windows app using this . Please share your code – Sukhangad singh Feb 18 '20 at 05:33
-
Windows app means desktop application not mobile application. I guess you are talking about Mobile app because mobile must have TouchScreen Functionality. – Neh18 Feb 18 '20 at 06:25