Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
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

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

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