select_by_value

The command to select an <option> by its value within a <select> dropdown element.

Syntax

Element.select_by_value(value: Any) -> Element

Usage

correct usage
py.get("#dropdown").select_by_value(2)

---or--- # chain an Element command

py.get("#dropdown").select_by_value("1").get_attribute("value")
incorrect usage
# Errors, can only perform this command on a <select> dropdown element
py.get("ul > li").select_by_value("2")

Arguments

  • value (Any) - The value of the option to select. Usually a str, but can be other types.

Yields

  • Element - The current instance of Element so you can chain commands.

Examples

Given this HTML

We can select any of the options

See also

Last updated