selenium.webdriver.support.ui¶
- class selenium.webdriver.support.ui.Select(webelement: WebElement)[source]¶
Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.
- Args:
webelement - SELECT element to wrap
- Example:
from selenium.webdriver.support.ui import Select
Select(driver.find_element(By.TAG_NAME, “select”)).select_by_index(2)
- property options: List[WebElement]¶
Returns a list of all options belonging to this select tag.
- property all_selected_options: List[WebElement]¶
Returns a list of all selected options belonging to this select tag.
- property first_selected_option: WebElement¶
The first selected option in this select tag (or the currently selected option in a normal select)
- select_by_value(value: str) None [source]¶
Select all options that have a value matching the argument. That is, when given “foo” this would select an option like:
<option value=”foo”>Bar</option>
- Args:
value - The value to match against
throws NoSuchElementException If there is no option with specified value in SELECT
- select_by_index(index: int) None [source]¶
Select the option at the given index. This is done by examining the “index” attribute of an element, and not merely by counting.
- Args:
index - The option at this index will be selected
throws NoSuchElementException If there is no option with specified index in SELECT
- select_by_visible_text(text: str) None [source]¶
Select all options that display text matching the argument. That is, when given “Bar” this would select an option like:
<option value=”foo”>Bar</option>
- Args:
text - The visible text to match against
throws NoSuchElementException If there is no option with specified text in SELECT
- deselect_all() None [source]¶
Clear all selected entries.
This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections
- deselect_by_value(value: str) None [source]¶
Deselect all options that have a value matching the argument. That is, when given “foo” this would deselect an option like:
<option value=”foo”>Bar</option>
- Args:
value - The value to match against
throws NoSuchElementException If there is no option with specified value in SELECT
- deselect_by_index(index: int) None [source]¶
Deselect the option at the given index. This is done by examining the “index” attribute of an element, and not merely by counting.
- Args:
index - The option at this index will be deselected
throws NoSuchElementException If there is no option with specified index in SELECT
- class selenium.webdriver.support.ui.WebDriverWait(driver: D, timeout: float, poll_frequency: float = 0.5, ignored_exceptions: Iterable[Type[Exception]] | None = None)[source]¶
Constructor, takes a WebDriver instance and timeout in seconds.
- Args:
driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote) or a WebElement
timeout - Number of seconds before timing out
poll_frequency - sleep interval between calls By default, it is 0.5 second.
ignored_exceptions - iterable structure of exception classes ignored during calls. By default, it contains NoSuchElementException only.
Example:
from selenium.webdriver.support.wait import WebDriverWait element = WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "someId")) is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).\ until_not(lambda x: x.find_element(By.ID, "someId").is_displayed())
- until(method: Callable[[D], Literal[False] | T], message: str = '') T [source]¶
Calls the method provided with the driver as an argument until the return value does not evaluate to
False
.- Parameters:
method – callable(WebDriver)
message – optional message for
TimeoutException
- Returns:
the result of the last call to method
- Raises:
selenium.common.exceptions.TimeoutException
if timeout occurs
- until_not(method: Callable[[D], T], message: str = '') T | Literal[True] [source]¶
Calls the method provided with the driver as an argument until the return value evaluates to
False
.- Parameters:
method – callable(WebDriver)
message – optional message for
TimeoutException
- Returns:
the result of the last call to method, or
True
if method has raised one of the ignored exceptions- Raises:
selenium.common.exceptions.TimeoutException
if timeout occurs