unable to select value from dropdown list

**This is my selenium webdriver code**

package com.ej.zob.modules;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;
public class Employee {
public void Execute(String TopLink,String UserName,String Password,String Email,String CreatedOn, String RoleName,String FirstName,String LastName, String Company, String Phone ){
LaunchApplication.driver.findElement(By.className(TopLink)).click();
LaunchApplication.driver.findElement(By.id(“field-username”)).sendKeys(UserName);
LaunchApplication.driver.findElement(By.id(“field-password”)).sendKeys(Password);
LaunchApplication.driver.findElement(By.id(“field-email”)).sendKeys(Email);
LaunchApplication.driver.findElement(By.id(“field-created_on”)).sendKeys(CreatedOn);
//LaunchApplication.driver.findElement(By.tagName(“”)
LaunchApplication.driver.findElement(By.linkText(“Select Role Name”)).click();
LaunchApplication.driver.findElements(By.id(“field-role_name”));
//LaunchApplication.driver.findElement(By.className(“chzn-drop”));
//sel.selectByIndex(5);
//sel.selectByVisibleText(RoleName);
LaunchApplication.driver.findElement(By.id(“field-first_name”)).sendKeys(FirstName);
LaunchApplication.driver.findElement(By.id(“field-last_name”)).sendKeys(LastName);
LaunchApplication.driver.findElement(By.id(“field-company”)).sendKeys(Company);
LaunchApplication.driver.findElement(By.id(“field-phone”)).sendKeys(Phone);
//LaunchApplication.driver.findElement(By.id(“form-button-save”)).click();
}

}

**This is my html code**

<select id=”field-role_name” class=”chosen-select chzn-done”
data-placeholder=”Select Role Name” name=”role_name”
style=”display: none;”>

<option value=””></option>
<option value=”ADMIN”></option>
<option value=”BM”></option>
<option value=”SM”></option>
<option value=”BT”></option>
<option value=”ITOP”></option>
<option value=”GUEST”></option>
<option value=”COH”></option>
<option value=”BEOP”></option>
<option value=”SA”></option>
</select>

**I want to select the value from dropdown say “Admin”.Check the code of
field-role_name.**

abnimkar Default Asked on May 12, 2015 in Selenium WebDriver.
Add Comment
1 Answer(s)

Must use Select statement here.

Select sel=new Select(LaunchApplication.driver.findElement(By.id(“field-role_name”);
sel.selectByIndex(5);
OR
sel.selectByValue(“SM”);

sharon Default Answered on May 13, 2015.

Hi Sharon

<select id=”field-role_name” class=”chosen-select chzn-done”
data-placeholder=”Select Role Name” name=”role_name”
style=”display: none;”>
<option value=”SM”></option>
<option value=”BT”></option>

String valueis = “SM”
Select sel=new Select(LaunchApplication.driver.findElement(By.id(“field-role_name”)

sel.selectByValue(valueis);    or sel.selectByValue(“”+ valueis);    is not working Why ?

please advice me  if i want to choose  the drop down based on the String   value ?

on July 13, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.