I am getting error for drop down list

41 views
Skip to first unread message

Adarsh Kumar

unread,
Jul 27, 2016, 2:36:11 AM7/27/16
to Selenium Users

Hi ,

I am getting following error in web driver for the drop down list. I tried all the methods but same error. Please help me on this.

Unable to locate element:
Command duration or timeout: 280 milliseconds

Praveen iG

unread,
Jul 27, 2016, 2:39:08 AM7/27/16
to Selenium Users

Hi Adarsh,

Could you please provide more information? Either the URL of where you're trying this or the code snippet might help.

Regards,
Praveen G


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a1abc3d7-7c2a-42b5-a105-e0f0533a4123%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adarsh Kumar

unread,
Jul 27, 2016, 3:41:50 AM7/27/16
to Selenium Users
This is the code snippet 

<select name="ctl00$ContentPlaceHolder1$ddlTestSubject" id="ContentPlaceHolder1_ddlTestSubject" style="width:400px;">
		<option value="-1">-- Select --</option>
		<option value="1">101-Biochemistry</option>
		<option value="2">102-Biotechnology</option>
		<option value="3">103-Botany</option>
		<option value="4">104-Chemistry</option>
		<option value="5">105-Computer Science</option>
		<option value="6">106-Food Technology</option>
		<option value="7">107-Marine Biology</option>
		<option value="8">108-Mathematics</option>
		<option value="9">109-Physics</option>
		<option value="10">110-Statistics</option>
		<option value="11">111-Zoology</option>
		<option value="12">112-Microbiology</option>
		<option value="13">201-Commerce</option>
		<option value="14">202-Economics</option>
		<option value="15">203-Education</option>
		<option value="16">204-English</option>
		<option value="17">205-Political Science &amp; Public Administration</option>
		<option value="18">206-Social Work</option>
		<option value="19">207-Telugu</option>
		<option value="20">301-Integrated Biotechnology</option>
		<option value="21">302-Integrated Food Technology</option>
		<option value="22">303-Integrated Business Administration</option>
		<option value="23">401-Aquaculture</option>
		<option value="24">402-Journalism</option>
		<option value="25">403-Translation</option>

	</select>
                                
                                    <span id="ContentPlaceHolder1_RequiredFieldValidator43" style="color:Red;display:none;">Select the Subject</span>
                                </td>

Praveen iG

unread,
Jul 27, 2016, 4:44:23 AM7/27/16
to Selenium Users

Have you tried adding wait statements? 


Nagarjuna Madineni

unread,
Jul 27, 2016, 5:55:45 AM7/27/16
to Selenium Users
Hi Adarsh,

Based on your question, unable to locate the element like 280 milliseconds right.

Can you increase the waits to seconds instead of milliseconds.

Example: Your using Thread.sleep(1000 instead of Thread.sleep(1).

Mallik H

unread,
Jul 28, 2016, 11:29:20 AM7/28/16
to Selenium Users
Sample working code:

public static void main(String[] arg) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/myhtml.html");
Select select = new Select(driver.findElement(By.xpath("//select")));
// Dynamically select one of the available options
String strvalidSelectOption = null;
Integer iIndex =  new Random().nextInt(select.getOptions().size());
strvalidSelectOption = select.getOptions().get(iIndex).getText();
if(!strvalidSelectOption.contains("-- Select --"))
{
Thread.sleep(2000);
select.selectByVisibleText(strvalidSelectOption.trim());
}
else
{
iIndex =  new Random().nextInt(select.getOptions().size());
driver.findElement(By.xpath("//select")).click();
Thread.sleep(2000);
select.selectByValue(select.getOptions().get(iIndex).getText());

Mallik H

unread,
Jul 28, 2016, 11:29:58 AM7/28/16
to Selenium Users
Sample working code:

Reply all
Reply to author
Forward
0 new messages