これは、このセクションの複数ページの印刷可能なビューです。 印刷するには、ここをクリックしてください.

このページの通常のビューに戻る.

サポート機能

サポート クラスは、オプションの上位レベル機能を提供します。

The core libraries of Selenium try to be low level and non-opinionated. The Support classes in each language provide opinionated wrappers for common interactions that may be used to simplify some behaviors.

1 - Waiting with Expected Conditions

These are classes used to describe what needs to be waited for.

Expected Conditions are used with Explicit Waits. Instead of defining the block of code to be executed with a lambda, an expected conditions method can be created to represent common things that get waited on. Some methods take locators as arguments, others take elements as arguments.

These methods can include conditions such as:

  • element exists
  • element is stale
  • element is visible
  • text is visible
  • title contains specified value
[Expected Conditions Documentation](https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html)

Add Example

.NET stopped supporting Expected Conditions in Selenium 4 to minimize maintenance hassle and redundancy.
Ruby makes frequent use of blocks, procs and lambdas and does not need Expected Conditions classes

2 - Command Listeners

These allow you to execute custom actions in every time specific Selenium commands are sent

3 - 色を扱う

テストの一部として何かの色を検証したい場合があります。 問題は、ウェブ上の色の定義が一定ではないことです。 色のHEX表現を色のRGB表現と比較する簡単な方法、または色のRGBA表現を色のHSLA表現と比較する簡単な方法があったらいいのではないでしょうか?

心配しないでください。解決策があります。: Color クラスです!

まず、クラスをインポートする必要があります。

import org.openqa.selenium.support.Color;
  
from selenium.webdriver.support.color import Color
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
include Selenium::WebDriver::Support
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
import org.openqa.selenium.support.Color

これで、カラーオブジェクトの作成を開始できます。 すべての色オブジェクトは、色の文字列表現から作成する必要があります。 サポートされている色表現は、以下のとおりです。

private final Color HEX_COLOUR = Color.fromString("#2F7ED8");
private final Color RGB_COLOUR = Color.fromString("rgb(255, 255, 255)");
private final Color RGB_COLOUR = Color.fromString("rgb(40%, 20%, 40%)");
private final Color RGBA_COLOUR = Color.fromString("rgba(255, 255, 255, 0.5)");
private final Color RGBA_COLOUR = Color.fromString("rgba(40%, 20%, 40%, 0.5)");
private final Color HSL_COLOUR = Color.fromString("hsl(100, 0%, 50%)");
private final Color HSLA_COLOUR = Color.fromString("hsla(100, 0%, 50%, 0.5)");
  
HEX_COLOUR = Color.from_string('#2F7ED8')
RGB_COLOUR = Color.from_string('rgb(255, 255, 255)')
RGB_COLOUR = Color.from_string('rgb(40%, 20%, 40%)')
RGBA_COLOUR = Color.from_string('rgba(255, 255, 255, 0.5)')
RGBA_COLOUR = Color.from_string('rgba(40%, 20%, 40%, 0.5)')
HSL_COLOUR = Color.from_string('hsl(100, 0%, 50%)')
HSLA_COLOUR = Color.from_string('hsla(100, 0%, 50%, 0.5)')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
HEX_COLOUR = Color.from_string('#2F7ED8')
RGB_COLOUR = Color.from_string('rgb(255, 255, 255)')
RGB_COLOUR = Color.from_string('rgb(40%, 20%, 40%)')
RGBA_COLOUR = Color.from_string('rgba(255, 255, 255, 0.5)')
RGBA_COLOUR = Color.from_string('rgba(40%, 20%, 40%, 0.5)')
HSL_COLOUR = Color.from_string('hsl(100, 0%, 50%)')
HSLA_COLOUR = Color.from_string('hsla(100, 0%, 50%, 0.5)')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
private val HEX_COLOUR = Color.fromString("#2F7ED8")
private val RGB_COLOUR = Color.fromString("rgb(255, 255, 255)")
private val RGB_COLOUR_PERCENT = Color.fromString("rgb(40%, 20%, 40%)")
private val RGBA_COLOUR = Color.fromString("rgba(255, 255, 255, 0.5)")
private val RGBA_COLOUR_PERCENT = Color.fromString("rgba(40%, 20%, 40%, 0.5)")
private val HSL_COLOUR = Color.fromString("hsl(100, 0%, 50%)")
private val HSLA_COLOUR = Color.fromString("hsla(100, 0%, 50%, 0.5)")
  

Colorクラスは、 http://www.w3.org/TR/css3-color/#html4 で指定されているすべての基本色定義もサポートしています。

private final Color BLACK = Color.fromString("black");
private final Color CHOCOLATE = Color.fromString("chocolate");
private final Color HOTPINK = Color.fromString("hotpink");
  
BLACK = Color.from_string('black')
CHOCOLATE = Color.from_string('chocolate')
HOTPINK = Color.from_string('hotpink')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
BLACK = Color.from_string('black')
CHOCOLATE = Color.from_string('chocolate')
HOTPINK = Color.from_string('hotpink')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
private val BLACK = Color.fromString("black")
private val CHOCOLATE = Color.fromString("chocolate")
private val HOTPINK = Color.fromString("hotpink")
  

要素に色が設定されていない場合、ブラウザは “透明” の色の値を返すことがあります。 Colorクラスもこれをサポートしています。

private final Color TRANSPARENT = Color.fromString("transparent");
  
TRANSPARENT = Color.from_string('transparent')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
TRANSPARENT = Color.from_string('transparent')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
private val TRANSPARENT = Color.fromString("transparent")
  

レスポンスが正しく解析され、有効なColorオブジェクトに変換されることを認識して、要素を安全にクエリしてその色/背景色を取得できるようになりました。

Color loginButtonColour = Color.fromString(driver.findElement(By.id("login")).getCssValue("color"));

Color loginButtonBackgroundColour = Color.fromString(driver.findElement(By.id("login")).getCssValue("background-color"));
  
login_button_colour = Color.from_string(driver.find_element(By.ID,'login').value_of_css_property('color'))

login_button_background_colour = Color.from_string(driver.find_element(By.ID,'login').value_of_css_property('background-color'))
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
login_button_colour = Color.from_string(driver.find_element(id: 'login').css_value('color'))

login_button_background_colour = Color.from_string(driver.find_element(id: 'login').css_value('background-color'))
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
val loginButtonColour = Color.fromString(driver.findElement(By.id("login")).getCssValue("color"))

val loginButtonBackgroundColour = Color.fromString(driver.findElement(By.id("login")).getCssValue("background-color"))
  

そして、色オブジェクトを直接比較できます。

assert loginButtonBackgroundColour.equals(HOTPINK);
  
assert login_button_background_colour == HOTPINK
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
assert(login_button_background_colour == HOTPINK)
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
assert(loginButtonBackgroundColour.equals(HOTPINK))
  

または、色を次の形式のいずれかに変換し、静的に検証することができます。

assert loginButtonBackgroundColour.asHex().equals("#ff69b4");
assert loginButtonBackgroundColour.asRgba().equals("rgba(255, 105, 180, 1)");
assert loginButtonBackgroundColour.asRgb().equals("rgb(255, 105, 180)");
  
assert login_button_background_colour.hex == '#ff69b4'
assert login_button_background_colour.rgba == 'rgba(255, 105, 180, 1)'
assert login_button_background_colour.rgb == 'rgb(255, 105, 180)'
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
assert(login_button_background_colour.hex == '#ff69b4')
assert(login_button_background_colour.rgba == 'rgba(255, 105, 180, 1)')
assert(login_button_background_colour.rgb == 'rgb(255, 105, 180)')
  
// This feature is not implemented - Help us by sending a pr to implement this feature
  
assert(loginButtonBackgroundColour.asHex().equals("#ff69b4"))
assert(loginButtonBackgroundColour.asRgba().equals("rgba(255, 105, 180, 1)"))
assert(loginButtonBackgroundColour.asRgb().equals("rgb(255, 105, 180)"))
  

色はもはや問題ではありません。

4 - 選択要素の操作

選択リストには、他の要素と比較して特別な動作があります。

The Select object will now give you a series of commands that allow you to interact with a <select> element.

If you are using Java or .NET make sure that you’ve properly required the support package in your code. See the full code from GitHub in any of the examples below.

Note that this class only works for HTML elements select and option. It is possible to design drop-downs with JavaScript overlays using div or li, and this class will not work for those.

Types

Select methods may behave differently depending on which type of <select> element is being worked with.

Single select

This is the standard drop-down object where one and only one option may be selected.

<select name="selectomatic">
    <option selected="selected" id="non_multi_option" value="one">One</option>
    <option value="two">Two</option>
    <option value="four">Four</option>
    <option value="still learning how to count, apparently">Still learning how to count, apparently</option>
</select>

Multiple select

This select list allows selecting and deselecting more than one option at a time. This only applies to <select> elements with the multiple attribute.

<select name="multi" id="multi" multiple="multiple">
    <option selected="selected" value="eggs">Eggs</option>
    <option value="ham">Ham</option>
    <option selected="selected" value="sausages">Sausages</option>
    <option value="onion gravy">Onion gravy</option>
</select>

Create class

First locate a <select> element, then use it to initialize a Select object. Note that as of Selenium 4.5, you can’t create a Select object if the <select> element is disabled.

22
25
Show full example
package dev.selenium.support;

import dev.selenium.BaseChromeTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import java.util.ArrayList;
import java.util.List;

public class SelectListTest extends BaseChromeTest {

    @BeforeEach
    public void navigate() {
        driver.get("https://www.selenium.dev/selenium/web/formPage.html");
    }

    @Test
    public void selectOption() {
        WebElement selectElement = driver.findElement(By.name("selectomatic"));
        Select select = new Select(selectElement);

        WebElement twoElement = driver.findElement(By.cssSelector("option[value=two]"));
        WebElement fourElement = driver.findElement(By.cssSelector("option[value=four]"));
        WebElement countElement = driver.findElement(By.cssSelector("option[value='still learning how to count, apparently']"));

        select.selectByVisibleText("Four");
        Assertions.assertTrue(fourElement.isSelected());

        select.selectByValue("two");
        Assertions.assertTrue(twoElement.isSelected());

        select.selectByIndex(3);
        Assertions.assertTrue(countElement.isSelected());
    }

    @Test
    public void selectMultipleOption() {
        WebElement selectElement = driver.findElement(By.name("multi"));
        Select select = new Select(selectElement);

        WebElement hamElement = driver.findElement(By.cssSelector("option[value=ham]"));
        WebElement gravyElement = driver.findElement(By.cssSelector("option[value='onion gravy']"));
        WebElement eggElement = driver.findElement(By.cssSelector("option[value=eggs]"));
        WebElement sausageElement = driver.findElement(By.cssSelector("option[value='sausages']"));

        List<WebElement> optionElements = selectElement.findElements(By.tagName("option"));
        List<WebElement> optionList = select.getOptions();
        Assertions.assertEquals(optionElements, optionList);

        List<WebElement> selectedOptionList = select.getAllSelectedOptions();
        List<WebElement> expectedSelection = new ArrayList<WebElement>() {{
            add(eggElement);
            add(sausageElement);
        }};
        Assertions.assertEquals(expectedSelection, selectedOptionList);

        select.selectByValue("ham");
        select.selectByValue("onion gravy");
        Assertions.assertTrue(hamElement.isSelected());
        Assertions.assertTrue(gravyElement.isSelected());

        select.deselectByValue("eggs");
        select.deselectByValue("sausages");
        Assertions.assertFalse(eggElement.isSelected());
        Assertions.assertFalse(sausageElement.isSelected());
    }

    @Test
    public void disabledOption() {
        WebElement selectElement = driver.findElement(By.name("single_disabled"));
        Select select = new Select(selectElement);

        Assertions.assertThrows(UnsupportedOperationException.class, () -> {
            select.selectByValue("disabled");
        });
    }
}
8
11
<details class="mt-3">
  <summary>Show full example</summary>
  <div class="pt-2">
    <div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">pytest</span>

from selenium.webdriver.common.by import By from selenium.webdriver.support.select import Select def test_select_options(driver): driver.get('https://selenium.dev/selenium/web/formPage.html') select_element = driver.find_element(By.NAME, 'selectomatic') select = Select(select_element) two_element = driver.find_element(By.CSS_SELECTOR, 'option[value=two]') four_element = driver.find_element(By.CSS_SELECTOR, 'option[value=four]') count_element = driver.find_element(By.CSS_SELECTOR, "option[value='still learning how to count, apparently']") select.select_by_visible_text('Four') assert four_element.is_selected() select.select_by_value('two') assert two_element.is_selected() select.select_by_index(3) assert count_element.is_selected() def test_select_multiple_options(driver): driver.get('https://selenium.dev/selenium/web/formPage.html') select_element = driver.find_element(By.NAME, 'multi') select = Select(select_element) ham_element = driver.find_element(By.CSS_SELECTOR, 'option[value=ham]') gravy_element = driver.find_element(By.CSS_SELECTOR, "option[value='onion gravy']") egg_element = driver.find_element(By.CSS_SELECTOR, 'option[value=eggs]') sausage_element = driver.find_element(By.CSS_SELECTOR, "option[value='sausages']") option_elements = select_element.find_elements(By.TAG_NAME, 'option') option_list = select.options assert option_elements == option_list selected_option_list = select.all_selected_options expected_selection = [egg_element, sausage_element] assert selected_option_list == expected_selection select.select_by_value('ham') select.select_by_value('onion gravy') assert ham_element.is_selected() assert gravy_element.is_selected() select.deselect_by_value('eggs') select.deselect_by_value('sausages') assert not egg_element.is_selected() assert not sausage_element.is_selected() def test_disabled_options(driver): driver.get('https://selenium.dev/selenium/web/formPage.html') select_element = driver.find_element(By.NAME, 'single_disabled') select = Select(select_element) with pytest.raises(NotImplementedError): select.select_by_value('disabled')

<div class="text-end pb-2 mt-2">
  <a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/support/test_select_list.py#L9-L10" target="_blank">
    <i class="fas fa-external-link-alt pl-2"></i>
    <strong>View full example on GitHub</strong>
  </a>
</div>
22
25
Show full example
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

namespace SeleniumDocs.Support
{
    [TestClass]
    public class SelectListTest : BaseChromeTest
    {
        [TestInitialize]
        public void Navigate()
        {
            driver.Url = "https://www.selenium.dev/selenium/web/formPage.html";
        }

        [TestMethod]
        public void SelectOption()
        {
            var selectElement = driver.FindElement(By.Name("selectomatic"));
            var select = new SelectElement(selectElement);

            var twoElement = driver.FindElement(By.CssSelector("option[value=two]"));
            var fourElement = driver.FindElement(By.CssSelector("option[value=four]"));
            var countElement = driver.FindElement(By.CssSelector("option[value='still learning how to count, apparently']"));

            select.SelectByText("Four");
            Assert.IsTrue(fourElement.Selected);

            select.SelectByValue("two");
            Assert.IsTrue(twoElement.Selected);

            select.SelectByIndex(3);
            Assert.IsTrue(countElement.Selected);

        }

        [TestMethod]
        public void SelectMultipleOption()
        {
            var selectElement = driver.FindElement(By.Name("multi"));
            var select = new SelectElement(selectElement);

            var hamElement = driver.FindElement(By.CssSelector("option[value=ham]"));
            var gravyElement = driver.FindElement(By.CssSelector("option[value='onion gravy']"));
            var eggElement = driver.FindElement(By.CssSelector("option[value=eggs]"));
            var sausageElement = driver.FindElement(By.CssSelector("option[value='sausages']"));

            IList<IWebElement> optionList = select.Options;
            IWebElement[] optionElements = selectElement.FindElements(By.TagName("option")).ToArray();
            CollectionAssert.AreEqual(optionElements, optionList.ToArray());

            IList<IWebElement> selectedOptionList = select.AllSelectedOptions;
            IWebElement[] expectedSelection = { eggElement, sausageElement };
            CollectionAssert.AreEqual(expectedSelection, selectedOptionList.ToArray());

            select.SelectByValue("ham");
            select.SelectByValue("onion gravy");
            Assert.IsTrue(hamElement.Selected);
            Assert.IsTrue(gravyElement.Selected);

            select.DeselectByValue("eggs");
            select.DeselectByValue("sausages");
            Assert.IsFalse(eggElement.Selected);
            Assert.IsFalse(sausageElement.Selected);
        }

        [TestMethod]
        public void DisabledOption()
        {
            var selectElement = driver.FindElement(By.Name("single_disabled"));
            var select = new SelectElement(selectElement);

            Assert.ThrowsException<InvalidOperationException>(() => select.SelectByValue("disabled"));
        }
    }
}
12
15
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Select List' do
  let(:driver) { start_session }

  before do
    driver.get('https://www.selenium.dev/selenium/web/formPage.html')
  end

  it 'select options' do
    select_element = driver.find_element(name: 'selectomatic')
    select = Selenium::WebDriver::Support::Select.new(select_element)

    two_element = driver.find_element(css: 'option[value=two]')
    four_element = driver.find_element(css: 'option[value=four]')
    count_element = driver.find_element(css: "option[value='still learning how to count, apparently']")

    select.select_by(:text, 'Four')
    expect(four_element).to be_selected

    select.select_by(:value, 'two')
    expect(two_element).to be_selected

    select.select_by(:index, 3)
    expect(count_element).to be_selected
  end

  it 'select multiple options' do
    select_element = driver.find_element(name: 'multi')
    select = Selenium::WebDriver::Support::Select.new(select_element)

    ham_element = driver.find_element(css: 'option[value=ham]')
    gravy_element = driver.find_element(css: "option[value='onion gravy']")
    egg_element = driver.find_element(css: 'option[value=eggs]')
    sausage_element = driver.find_element(css: "option[value='sausages']")

    option_elements = select_element.find_elements(tag_name: 'option')
    option_list = select.options
    expect(option_elements).to eq option_list

    selected_option_list = select.selected_options
    expected_selection = [egg_element, sausage_element]
    expect(selected_option_list).to eq expected_selection

    select.select_by(:value, 'ham')
    select.select_by(:value, 'onion gravy')
    expect(ham_element).to be_selected
    expect(gravy_element).to be_selected

    select.deselect_by(:value, 'eggs')
    select.deselect_by(:value, 'sausages')
    expect(egg_element).not_to be_selected
    expect(sausage_element).not_to be_selected
  end

  it 'disabled options' do
    select_element = driver.find_element(name: 'single_disabled')
    select = Selenium::WebDriver::Support::Select.new(select_element)

    expect {
      select.select_by(:value, 'disabled')
    }.to raise_exception(Selenium::WebDriver::Error::UnsupportedOperationError)
  end
end
17
20
Show full example

const {By, Browser, Builder} = require('selenium-webdriver')
const assert = require('assert/strict')
const {Select} = require('selenium-webdriver')


describe('Select Tests', async function () {
  let driver

  before(async function () {
    driver = new Builder()
      .forBrowser(Browser.FIREFOX)
      .build()
    await driver.get('https://www.selenium.dev/selenium/web/formPage.html')
  })

  after(async () => await driver.quit())

  it('Select an option', async function () {
    const selectElement = await driver.findElement(By.name('selectomatic'))
    const select = new Select(selectElement)

    const twoElement = await driver.findElement(By.css('option[value=two]'))
    const fourElement = await driver.findElement(By.css('option[value=four]'))
    const countElement = await driver.findElement(By.css("option[value='still learning how to count, apparently']"))

    await select.selectByVisibleText('Four')
    assert.equal(true, await fourElement.isSelected())

    await select.selectByValue('two')
    assert.equal(true, await twoElement.isSelected())

    await select.selectByIndex(3)
    assert.equal(true, await countElement.isSelected())
  })

  it('Select by multiple options', async function () {
    const selectElement = await driver.findElement(By.name('multi'))
    const select = await new Select(selectElement)

    const hamElement = await driver.findElement(By.css('option[value=ham]'))
    const gravyElement = await driver.findElement(By.css("option[value='onion gravy']"))
    const eggElement = await driver.findElement(By.css('option[value=eggs]'))
    const sausageElement = await driver.findElement(By.css("option[value='sausages']"))

    const optionElements = await selectElement.findElements(By.css('option'))
    const optionList = await select.getOptions()
    assert.equal(optionList.length, optionElements.length)
    for (const index in optionList) {
      assert.equal(await optionList[index].getText(), await optionElements[index].getText())
    }

    const selectedOptionList = await select.getAllSelectedOptions()
    const expectedSelection = [eggElement, sausageElement]
    assert.equal(expectedSelection.length, selectedOptionList.length)
    for (const index in selectedOptionList) {
      assert.equal(await selectedOptionList[index].getText(), await expectedSelection[index].getText())
    }

    await select.selectByValue('ham')
    await select.selectByValue('onion gravy')
    assert.equal(true, await hamElement.isSelected())
    assert.equal(true, await gravyElement.isSelected())

    await select.deselectByValue('eggs')
    await select.deselectByValue('sausages')
    assert.equal(false, await eggElement.isSelected())
    assert.equal(false, await sausageElement.isSelected())
  })

  it('Try selecting disabled option', async function () {
    const selectElement = await driver.findElement(By.name('single_disabled'))
    const select = await new Select(selectElement)

    await assert.rejects(async () => {
      await select.selectByValue("disabled")
    }, {
      name: 'UnsupportedOperationError',
      message: 'You may not select a disabled option'
    })
  })
})
19
22
Show full example
package dev.selenium.support

import dev.selenium.BaseTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.ui.Select

class SelectListTest : BaseTest() {
  
  @BeforeEach
  fun navigate() {
    driver.get("https://www.selenium.dev/selenium/web/formPage.html")
  }
  
  @Test
  fun selectOption() {
    val selectElement = driver.findElement(By.name("selectomatic"))
    val select = Select(selectElement)
    
    val twoElement = driver.findElement(By.cssSelector("option[value=two]"))
    val fourElement = driver.findElement(By.cssSelector("option[value=four]"))
    val countElement = driver.findElement(By.cssSelector("option[value='still learning how to count, apparently']"))
    
    select.selectByVisibleText("Four")
    Assertions.assertTrue(fourElement.isSelected())

    select.selectByValue("two")
    Assertions.assertTrue(twoElement.isSelected())

    select.selectByIndex(3)
    Assertions.assertTrue(countElement.isSelected())
  }
  
  @Test
  fun selectMultipleOption() {
    val selectElement = driver.findElement(By.name("multi"))
    val select = Select(selectElement)
    
    val hamElement = driver.findElement(By.cssSelector("option[value=ham]"))
    val gravyElement = driver.findElement(By.cssSelector("option[value='onion gravy']"))
    val eggElement = driver.findElement(By.cssSelector("option[value=eggs]"))
    val sausageElement = driver.findElement(By.cssSelector("option[value='sausages']"))

    val optionElements = selectElement.findElements(By.tagName("option"))
    val optionList = select.getOptions()
    Assertions.assertEquals(optionElements, optionList)

    val selectedOptionList = select.getAllSelectedOptions()
    val expectedSelection = ArrayList<WebElement>() 
      expectedSelection.add(eggElement)
      expectedSelection.add(sausageElement)

    Assertions.assertEquals(expectedSelection, selectedOptionList)

    select.selectByValue("ham")
    select.selectByValue("onion gravy")
    Assertions.assertTrue(hamElement.isSelected())
    Assertions.assertTrue(gravyElement.isSelected())

    select.deselectByValue("eggs")
    select.deselectByValue("sausages")
    Assertions.assertFalse(eggElement.isSelected())
    Assertions.assertFalse(sausageElement.isSelected())
  }

  @Test
  fun disabledOption() {
    val selectElement = driver.findElement(By.name("single_disabled"))
    val select = Select(selectElement)
    
    Assertions.assertThrows(UnsupportedOperationException::class.java) {
      select.selectByValue("disabled")
    }
  }
}