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

Unable to select the list items in dropdown #182

Open
krishnakanth19 opened this issue Aug 30, 2017 · 17 comments
Open

Unable to select the list items in dropdown #182

krishnakanth19 opened this issue Aug 30, 2017 · 17 comments

Comments

@krishnakanth19
Copy link

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

@carolcruzc
Copy link

See if this issue helps you:
#73

@krishnakanth19
Copy link
Author

krishnakanth19 commented Sep 11, 2017

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();
}`

@heilwood
Copy link

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

@krishnakanth19
Copy link
Author

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

@heilwood
Copy link

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

@krishnakanth19
Copy link
Author

How to know that element has scroll pattern?

@Bala810R
Copy link

@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

@krishnakanth19
Copy link
Author

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.

@mheshvelpuri
Copy link

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

@krishnakanth19
Copy link
Author

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.

@srinivask91
Copy link

srinivask91 commented Jan 2, 2018

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

@srinivask91
Copy link

srinivask91 commented Jan 2, 2018

Hi heilwood,

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

@mheshvelpuri
Copy link

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].

@krishnakanth19
Copy link
Author

krishnakanth19 commented Jan 4, 2018

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.

@nagaprasad1987
Copy link

nagaprasad1987 commented Oct 9, 2020

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

@yaseentest
Copy link

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

@ProfoundPenguin
Copy link

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

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

9 participants