Select List Assertions

Learn how to assert a select list using Selenium, and try it out yourself.

Assert a label or a value in a select list

We can verify a label or a value in a select list by the following script:

my_select = driver.find_element(:id, "car_make_select")
select_texts = my_select.find_elements( :tag_name => "option" ).collect{|option|  
   option.text }
expect(select_texts.include?("Audi (Germany)")).to be_truthy

select_values = my_select.find_elements( :tag_name => "option" ).collect{|option|  
  option["value"] }
expect(select_values.include?("audi")).to be_truthy

However, there is another quicker and more simpler approach available to this as well:

var selElem = driver.findElement(By.name("car_make"))
selElem.sendKeys("Honda");  
selElem.getAttribute('value').then(function(selected) {
  assert.equal("honda", selected)
});

Get hands-on with 1200+ tech skills courses.