Winium.Desktop icon indicating copy to clipboard operation
Winium.Desktop copied to clipboard

Unable to select the list items in dropdown

Open krishnakanth19 opened this issue 6 years ago • 18 comments

Hi,

While selecting the location I’m able to click on the list items which are visible. But I’m unable to select the other locations in the dropdown list. When trying to select other location in dropdown list which is not visible in the drop-down, it is clicking somewhere else.

I.e. I’m able to click the list items up to “CARTAGE LA” (the location in dropdown list are visible up to CARTAGE LA). For the other locations, it is clicking outside the list.

WebElement ele = driver.findElement(By.id("cmbLocation")); ComboBox combo = new ComboBox(ele); combo.expand(); List<WebElement> lis = ele.findElements(By.className("ListBoxItem")); lis.get(42).click();

I used list index to locate elements. How can I locate them with visible text? I used the following code but it's not working.

WebElement ele = driver.findElement(By.id("cmbLocation")); ComboBox combo = new ComboBox(ele); combo.expand(); List<WebElement> lis = ele.findElements(By.className("ListBoxItem")); for(int i = 0; i< lis.size(); i++) { WebElement elem = lis.get(i).findElement(By.name("ATLANTA")); if("ATLANTA".contains(elem.getText())) { lis.get(i).click(); break; } }

image

krishnakanth19 avatar Aug 30 '17 06:08 krishnakanth19

Hello, Unfortunately I do not know how to help you. I did not develop the desktop automation application, I'm just posting the possibility of using it, since most people are unaware.

I also had difficulties in some moments. To get around it, I tried to use another way to identify my field, for example, by name or class. Most of the time it works for me.

*Carol Cruz de Carvalho * ​ https://www.linkedin.com/in/carolcruz +55 21 98710-7727

On Wed, Aug 30, 2017 at 3:45 AM, krishnakanth19 [email protected] wrote:

Hi,

While selecting the location I’m able to click on the list items which are visible. But I’m unable to select the other locations in the dropdown list. When trying to select other location in dropdown list which is not visible in the drop-down, it is clicking somewhere else.

I.e. I’m able to click the list items up to “CARTAGE LA” (the location in dropdown list are visible up to CARTAGE LA). For the other locations, it is clicking outside the list.

WebElement ele = driver.findElement(By.id("cmbLocation")); ComboBox combo = new ComboBox(ele); combo.expand(); List<WebElement> lis = ele.findElements(By.className("ListBoxItem")); lis.get(42).click();

I used list index to locate elements. How can I locate them with visible text? I used the following code but it's not working.

WebElement ele = driver.findElement(By.id("cmbLocation")); ComboBox combo = new ComboBox(ele); combo.expand(); List<WebElement> lis = ele.findElements(By.className("ListBoxItem")); for(int i = 0; i< lis.size(); i++) { WebElement elem = lis.get(i).findElement(By.name("ATLANTA")); if("ATLANTA".contains(elem.getText())) { lis.get(i).click(); break; } }

[image: image] https://user-images.githubusercontent.com/23556113/29858160-c56b6b78-8d79-11e7-8156-386b9cf0b89a.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/2gis/Winium.Desktop/issues/182, or mute the thread https://github.com/notifications/unsubscribe-auth/AdqrCGKMne3d-flX5GVkObGdJFKVHJgIks5sdQUjgaJpZM4PG78P .

carolcruzc avatar Aug 30 '17 13:08 carolcruzc

See if this issue helps you: https://github.com/2gis/Winium.Desktop/pull/73

carolcruzc avatar Aug 30 '17 13:08 carolcruzc

I used the index for selecting the dropdown list. It's working fine. The following is the code. public void selectLocation(WiniumDriver driver) { WebElement ele = driver.findElement(By.id("cmbLocation")); ComboBox combo = new ComboBox(ele); combo.expand(); List<WebElement> lis = ele.findElements(By.className("ListBoxItem")); lis.get(2).click(); }` But, when I'm trying to select to other locations which are below, it is clicking outside the dropdown list. Ex: In the list, it is showing locations up to "CARTAGR LA", there are more locations below it. When I try to access them by using the index, it is not scrolling down so, it is clicking outside the dropdown list.

public void selectLocation(WiniumDriver driver) { WebElement ele = driver.findElement(By.id("cmbLocation")); ComboBox combo = new ComboBox(ele); combo.expand(); List<WebElement> lis = ele.findElements(By.className("ListBoxItem")); lis.get(15).click(); }`

krishnakanth19 avatar Sep 11 '17 07:09 krishnakanth19

try to press page down button until your element will be clickable and then click on this element.

heilwood avatar Sep 26 '17 16:09 heilwood

I already tried that and it's working. But I'm looking for other solutions.

krishnakanth19 avatar Sep 27 '17 09:09 krishnakanth19

if your element don't have scrollPattern then its impossible to scroll in different way

heilwood avatar Sep 27 '17 09:09 heilwood

How to know that element has scroll pattern?

krishnakanth19 avatar Sep 27 '17 10:09 krishnakanth19

@krishnakanth19 Can you please share code snippet of how page down can be used in the code? When we attempt to perform any key combo actions like Ctrl+g (application internal command) it acts like Ctrl+A and selects all the form.

@heilwood, Ours is a windows application inside which webforms are rendered. We are able to perform send_keys method to type on fields inside Webforms fields (shown in image 2). However any key combo like page down, page up, ctrl + g with the step as "find_element(webpanel_locator).send_keys :page_down"

doesn't work

application hierarchy with winform webform

Bala810R avatar Oct 10 '17 16:10 Bala810R

I don't write any code for that. My issue is when I'm trying to select an item in the dropdown list which is hidden. It is not scrolling and clicking outside the dropdown list. In case of selenium, it will automatically scroll down.

krishnakanth19 avatar Oct 18 '17 13:10 krishnakanth19

Hi krishnakanth19 , I am facing the same problem. can you help me now?

mheshvelpuri avatar Dec 28 '17 06:12 mheshvelpuri

Hi mheshvelpuri,

I don't get proper solution for that. I'm reading all elements into a list and iterating throw it to click on a particular drop down item. If the element is hidden in the drop-down it is failing. So, if the element is hidden, I first call a method to scroll down and then clicks on that.

krishnakanth19 avatar Jan 02 '18 05:01 krishnakanth19

Hi krishnakanth19 Could you please share the idea of how you are scrolling down a combobox

srinivask91 avatar Jan 02 '18 06:01 srinivask91

Hi heilwood,

Could you please share your idea on scrolling an element which has scroll pattern.

srinivask91 avatar Jan 02 '18 06:01 srinivask91

Hi krishnakanth19, I tried your idea of verifying weather element is hidden or not.

But, when the combo box is loaded with huge number of options, not all the options are getting loaded after expanding the combobox.

Suppose if you have 40 options, only first 25 of the elements are getting identified. elements from 26th position to 40th position are throwing NoSuchElement Exception. Then, if I scroll to 10th element, elements from 5th position to 30th position are getting identified, first 4 elements and last 10 elements are throw NoSuchElement Exception.

Here, I am looking for identifying all the elements at a time and throw NoSuchElement Exception if the target element is out of those all 40 options. [like selectByVisibleText from Select class].

mheshvelpuri avatar Jan 03 '18 07:01 mheshvelpuri

Hi srinivask91,

The following is the code I used to scroll down. I used click events on the page down until element is visible and then clicked on that element. public void scrollDown() { WebElement ele = driver.findElement(By.id("PageDown")); ele.click(); ele.click(); } This is not the solution for this. It's just a quick fix.

krishnakanth19 avatar Jan 04 '18 10:01 krishnakanth19

Hi @krishnakanth19 Can you please let me know, how we can retrieve the selected name present at bottom of the list in the following image. image

nagaprasad1987 avatar Oct 09 '20 11:10 nagaprasad1987

getsize() will get only the dimensions of width and height of combobox.

yaseentest avatar Jun 08 '21 20:06 yaseentest

What about using Robot to scrollDown, or control the mouse wheel

ProfoundPenguin avatar Mar 05 '22 05:03 ProfoundPenguin