I have currently hit a stumbling block when trying to simply pick an option from a dropdown menu whilst automating a website.
Here is a snippet of the HTML:
<select id="alarm-dropdown" name="alarm-dropdown" data-bind="value: AlarmCode" data-ga-category="CarInsurance_YourVehicle_VehicleDetails_FittedWithAnAlarm" data-ga-action="Selected" data-ga-label="CarInsurance_YourVehicle_VehicleDetails_FittedWithAnAlarm">
<option class="" selected="" disabled="" value="">Please select...</option>
<option class="" id="alarm-dropdown-99991" value="99991">Factory Fitted Thatcham Approved Alarm/Immobiliser</option>
<option class="" id="alarm-dropdown-99992" value="99992">Factory Fitted Thatcham Approved Alarm</option>
<option class="" id="alarm-dropdown-99993" value="99993">Factory Fitted Non-Thatcham Alarm/Immobiliser</option>
<option class="" id="alarm-dropdown-99994" value="99994">Factory Fitted Non-Thatcham Alarm</option>
<option class="" id="alarm-dropdown-#F" value="#F">Factory Fitted</option>
<option class="" id="alarm-dropdown-#N" value="#N">None</option>
</select>
Here is my current code: -
Select select = new Select(driver.findElement(By.id("alarm-dropdown")));
select.selectByValue("Factory Fitted Non-Thatcham Alarm");
I have tried XPATH/ID/CSS
selectByValue()method - you are giving it the text instead. Instead ofFactory Fitted Non-Thatcham Alarmuse99994.NoSuchElementExceptionetc?element = driver.findElement(By.xpath("//*[@id=\"alarm-dropdown\"]")); element.click(); Select select = new Select(driver.findElement(By.id("alarm-dropdown"))); select.selectByValue("#F");Thanks guys Steve