Scroll Down a Drop down until element is visible [JAVA]

3,712 views
Skip to first unread message

raja

unread,
Jan 9, 2017, 6:21:20 AM1/9/17
to webdriver

Hi All,

I am trying to select a value in a drop down.


I have tried below code.  Below code is working fine for first 4 values as first four values are visible.

JavascriptExecutor je = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.tagName("...."));
je.executeScript("arguments[0].scrollIntoView(true);",element);



But the thing is element is visible only when we scroll down the dropdown.

In above code i am trying to find out the element which is not visible and not present at DOM.
Then i am getting the exception in second line itself.

Your suggestion is very valuable for me.

Waiting for your replies.


Regards,
Rajasekhar.

praveen kumar cherukuri

unread,
Jan 9, 2017, 6:38:11 AM1/9/17
to webd...@googlegroups.com
First Question: 
Are you using this code inside a FOR loop.? 
or Are you using it for a specific value from the drop-down.? 
or Are you using it with a specific index value for the entries of the drop-down.? 

Second Question: 
Why not try the default keywords from the Selenium API..? 

Select country = new Select(<<weblement_to_identify_dropdown); 

This will give a good coverage of different options like selection with index, visible text and value of the entries of the drop-down.

Would like to hear more from you about this. 

Good Luck, 
Praveen. 



--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+unsubscribe@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

Raja Sekhar

unread,
Jan 9, 2017, 9:13:06 AM1/9/17
to webd...@googlegroups.com
thanks for the reply.

if dropdown is developed by select tag, then your suggestion is perfectly work.

but in my case drop down is developed by div tag and again elements inside the dropdown also developed by div tag.

i am not using my code in any of the loops.

First I am clicking on drop down div and trying to select the drop down value.


darrell grainger

unread,
Jan 10, 2017, 1:22:57 PM1/10/17
to webdriver
This sounds like a UX fail to me. Why is development creating this structure which looks like a SELECT/OPTION element but is really using DIV and Javascript? Additionally, why are there more options on the list than will fit on the screen? Are they using an existing library to do this? Are they inventing there own library to do this? I, personally, fight against developers who just want to do something because they want a challenge or think it is cool. Re-inventing already existing technology with no real advantage is just adding unnecessary risk to a project. We conduct RAID meetings (Risk Action Issue Decision) to figure out how to mitigate risk. A story isn't DONE until it is written AND tested. If it cannot be economically tested then it is a bad implementation.

If you are doing real QA (and not just QC) or Delivery Assurance (DA) then pushing back on bad implementations is a viable solution. However if you are just a tester and silo'd away from development (not a good model at ALL) then we'd need to know more about how the structure is implemented (is there a GitHub site they have their library? Is there a demo site for a library development is using?). Without that it will be REALLY hard to implemented an automated solution to testing it.

Darrell
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.

To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.

Suresh Kumar

unread,
Jan 19, 2017, 1:49:14 AM1/19/17
to webdriver
Hi Raja, 

Try to execute a javascript to view the element in the console(eg: jQuery("code to view the element")) and try to execute the same javascript using driver.execute("jQuery(\"code to view the element\")") script
Reply all
Reply to author
Forward
0 new messages