Reputation: 3
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
Upvotes: 0
Views: 127
Reputation: 1487
Select select = new Select(driver.findElement(By.id("alarm-dropdown")));
select.selectByValue("99994");
Upvotes: 1
Reputation: 3461
Try with the xpath:
driver.findElement(By.xpath("//select[@id='alarm-dropdown']/option[@value='99994']")).click();
Upvotes: 0