Search
Display results as :
Advanced Search
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
Mahi_Selenium
Posts : 2
Join date : 2012-08-24

Can any one one help me to select drop down value using selenium webdriver Empty Can any one one help me to select drop down value using selenium webdriver

on Tue Sep 11, 2012 9:22 am
Hi,
I'm new to selenium. Can any one help me to select value from drop down boxes for below code.
Below one is the HTML Source code:

I have written below to do above Task:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumWebDriver {
public static void main(String[] args) throws Exception{
String baseURL="https://xxx.com/";
WebDriver driver=new FirefoxDriver();
driver.get(baseURL);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_UsernameTextBox")).sendKeys("MahendraP");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_PasswordTextBox")).sendKeys("Mahendra");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_SubmitButton")).click();
driver.findElement(By.id("cssi_newtimespent")).click();
http://driver.findElement(By.id("viewSel")).sendKeys("Active Time Spent");
WebElement select = driver.findElement(By.id("AppSystemViews"));
List options = select.findElements(By.tagName("option"));
for (WebElement option : options) {

if("Active Time Spent".equals(option.getText()))
{System.out.println(option.getText());
driver.findElement(By.id("viewSel")).click();
option.click();
}
else
System.out.println("Mahendra");
}
}
}
I'm getting below error while using above code:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cssi_newtimespent"}
Command duration or timeout: 328 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 17:28:14'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24'
Driver info: driver.version: SeleniumWebDriver
Session ID: f71ce402-3f3b-4a65-a9ef-a561c5493b88
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:271)
at org.openqa.selenium.By$ById.findElement(By.java:215)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:234)
at SeleniumWebDriver.main(SeleniumWebDriver.java:15)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"id","selector":"cssi_newtimespent"}
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 17:28:14'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24'
Driver info: driver.version: unknown
at .(file:///C:/DOCUME~1/Mahendra/LOCALS~1/Temp/anonymous298848908853356202webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:6556)
at .(file:///C:/DOCUME~1/Mahendra/LOCALS~1/Temp/anonymous298848908853356202webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:6564)
at .(file:///C:/DOCUME~1/Mahendra/LOCALS~1/Temp/anonymous298848908853356202webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10055)
at .(file:///C:/DOCUME~1/Mahendra/LOCALS~1/Temp/anonymous298848908853356202webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10060)
at .(file:///C:/DOCUME~1/Mahendra/LOCALS~1/Temp/anonymous298848908853356202webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:9998)

Guys please help me............
avatar
SunnyBoy
Posts : 3
Join date : 2013-03-20

Can any one one help me to select drop down value using selenium webdriver Empty Re: Can any one one help me to select drop down value using selenium webdriver

on Wed Mar 20, 2013 7:40 pm
Hi

This may help you try out...

public static boolean fnSelectValue(WebElement we, String sVal){
boolean obj = false;

Select select = new Select(we);
List options = select.getOptions();

for (WebElement sList : options) {

if (sList.getText().trim().equalsIgnoreCase(sVal.trim())) {
we.sendKeys(sVal);

if ((sVal).equals(select.getFirstSelectedOption().getText())) {
obj = true;
} else {
obj = false;}
break;

} else {
obj = false; }

}

return obj;
}
Back to top
Permissions in this forum:
You cannot reply to topics in this forum