简体   繁体   English

如何使用c#在Winapp驱动程序中滚动下拉和列表框等区域?

[英]How to scroll the area like drop down and list box in Winapp driver with c#?

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.我正在使用 WinAppdriver、appium、c# 和 MSTest。 I need such lines of code with which list will scroll till the element finds.我需要这样的代码行,列表将滚动直到找到元素。

滚动列表框

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.你可以用winappdriver找到你的元素,它会自动滚动到元素,我已经自动化了一个windows应用程序,它有一个接受文件的输入框,并在点击浏览按钮后有一个浏览器按钮,它本身滚动直到找到元素。

Regarding the code you may just try finding the element normal like it is in view .关于代码,您可以尝试找到正常的元素,就像它在视图中一样。

Hope this helps.希望这可以帮助。 :) :)

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".列表框具有辅助功能项“lbStates”。 We want to click the item "NC" in it which has the text "NC".我们要单击其中包含文本“NC”的项目“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.我们可以单击ListBox中的向下按钮向下滚动,或者我们可以按下按键按钮并测试我们要单击的值是否显示。 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.我们想要点击的值可能不存在于列表框中,在这种情况下,我们的代码将陷入死锁,为此我引入了整数 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();
                        }
                    }
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM