selenium.webdriver.support.relative_locator¶
Functions
|
Start searching for relative objects your search criteria with By. |
|
Start searching for relative objects using a tag name. |
Classes
|
Gives the opportunity to find elements based on their relative location on the page from a root elelemt. |
- selenium.webdriver.support.relative_locator.with_tag_name(tag_name: str) RelativeBy [source]¶
Start searching for relative objects using a tag name.
Note: This method may be removed in future versions, please use locate_with instead. :Args:
tag_name: the DOM tag of element to start searching.
- Returns:
- RelativeBy - use this object to create filters within a
find_elements call.
- selenium.webdriver.support.relative_locator.locate_with(by: Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'], using: str) RelativeBy [source]¶
Start searching for relative objects your search criteria with By.
- Args:
by: The value from By passed in.
using: search term to find the element with.
- Returns:
- RelativeBy - use this object to create filters within a
find_elements call.
- class selenium.webdriver.support.relative_locator.RelativeBy(root: Dict[Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'], str] | None = None, filters: List | None = None)[source]¶
Gives the opportunity to find elements based on their relative location on the page from a root elelemt. It is recommended that you use the helper function to create it.
- Example:
lowest = driver.find_element(By.ID, “below”)
elements = driver.find_elements(locate_with(By.CSS_SELECTOR, “p”).above(lowest))
ids = [el.get_attribute(‘id’) for el in elements] assert “above” in ids assert “mid” in ids
Creates a new RelativeBy object. It is preferred if you use the locate_with method as this signature could change.
- Args:
root - A dict with By enum as the key and the search query as the value filters - A list of the filters that will be searched. If none are passed
in please use the fluent API on the object to create the filters
- LocatorType¶
alias of
Dict
[Literal
[‘id’, ‘xpath’, ‘link text’, ‘partial link text’, ‘name’, ‘tag name’, ‘class name’, ‘css selector’],str
]
- above(element_or_locator: WebElement | LocatorType) RelativeBy [source]¶
- above(element_or_locator: None = None) NoReturn
Add a filter to look for elements above.
- Args:
element_or_locator: Element to look above
- below(element_or_locator: WebElement | LocatorType) RelativeBy [source]¶
- below(element_or_locator: None = None) NoReturn
Add a filter to look for elements below.
- Args:
element_or_locator: Element to look below
- to_left_of(element_or_locator: WebElement | LocatorType) RelativeBy [source]¶
- to_left_of(element_or_locator: None = None) NoReturn
Add a filter to look for elements to the left of.
- Args:
element_or_locator: Element to look to the left of
- to_right_of(element_or_locator: WebElement | LocatorType) RelativeBy [source]¶
- to_right_of(element_or_locator: None = None) NoReturn
Add a filter to look for elements right of.
- Args:
element_or_locator: Element to look right of
- near(element_or_locator: WebElement | LocatorType, distance: int = 50) RelativeBy [source]¶
- near(element_or_locator: None = None, distance: int = 50) NoReturn
Add a filter to look for elements near.
- Args:
element_or_locator: Element to look near by the element or within a distance
distance: distance in pixel