Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

View previous topic View next topic Go down

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

Post by Mahi_Selenium 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............

Mahi_Selenium

Posts : 2
Join date : 2012-08-24

Back to top Go down

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

Post by SunnyBoy 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;
}

SunnyBoy

Posts : 3
Join date : 2013-03-20

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum