Skip to content

Commit

Permalink
[py]: remove deprecated find_element_by_ methods (#10712)
Browse files Browse the repository at this point in the history
  • Loading branch information
symonk authored Jun 8, 2022
1 parent 38e8963 commit 4bbb7c2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 890 deletions.
383 changes: 0 additions & 383 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,389 +453,6 @@ def title(self) -> str:
resp = self.execute(Command.GET_TITLE)
return resp['value'] if resp['value'] else ""

def find_element_by_id(self, id_) -> WebElement:
"""Finds an element by id.
:Args:
- id\\_ - The id of the element to be found.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_id('foo')
"""
warnings.warn(
"find_element_by_* commands are deprecated. Please use find_element() instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.ID, value=id_)

def find_elements_by_id(self, id_) -> List[WebElement]:
"""
Finds multiple elements by id.
:Args:
- id\\_ - The id of the elements to be found.
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_id('foo')
"""
warnings.warn(
"find_elements_by_id is deprecated. Please use find_elements(by=By.ID, value=id_) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.ID, value=id_)

def find_element_by_xpath(self, xpath) -> WebElement:
"""
Finds an element by xpath.
:Args:
- xpath - The xpath locator of the element to find.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_xpath('//div/td[1]')
"""
warnings.warn(
"find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.XPATH, value=xpath)

def find_elements_by_xpath(self, xpath) -> List[WebElement]:

This comment has been minimized.

Copy link
@vvelusamy1

vvelusamy1 Jun 24, 2022

this is impacting seleniumlibrary versions used in https://github.com/robotframework/SeleniumLibrary . Since this is removed, what else is the alternative method.

This comment has been minimized.

Copy link
@vvelusamy1

vvelusamy1 Jun 24, 2022

nvm. need some fixes from robot framework-appiumlibrary side to work on.

"""
Finds multiple elements by xpath.
:Args:
- xpath - The xpath locator of the elements to be found.
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_xpath("//div[contains(@class, 'foo')]")
"""
warnings.warn(
"find_elements_by_xpath is deprecated. Please use find_elements(by=By.XPATH, value=xpath) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.XPATH, value=xpath)

def find_element_by_link_text(self, link_text) -> WebElement:
"""
Finds an element by link text.
:Args:
- link_text: The text of the element to be found.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_link_text('Sign In')
"""
warnings.warn(
"find_element_by_link_text is deprecated. Please use find_element(by=By.LINK_TEXT, value=link_text) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.LINK_TEXT, value=link_text)

def find_elements_by_link_text(self, text) -> List[WebElement]:
"""
Finds elements by link text.
:Args:
- link_text: The text of the elements to be found.
:Returns:
- list of webelement - a list with elements if any was found. an
empty list if not
:Usage:
::
elements = driver.find_elements_by_link_text('Sign In')
"""
warnings.warn(
"find_elements_by_link_text is deprecated. Please use find_elements(by=By.LINK_TEXT, value=text) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.LINK_TEXT, value=text)

def find_element_by_partial_link_text(self, link_text) -> WebElement:
"""
Finds an element by a partial match of its link text.
:Args:
- link_text: The text of the element to partially match on.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_partial_link_text('Sign')
"""
warnings.warn(
"find_element_by_partial_link_text is deprecated. Please use find_element(by=By.PARTIAL_LINK_TEXT, value=link_text) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.PARTIAL_LINK_TEXT, value=link_text)

def find_elements_by_partial_link_text(self, link_text) -> List[WebElement]:
"""
Finds elements by a partial match of their link text.
:Args:
- link_text: The text of the element to partial match on.
:Returns:
- list of webelement - a list with elements if any was found. an
empty list if not
:Usage:
::
elements = driver.find_elements_by_partial_link_text('Sign')
"""
warnings.warn(
"find_elements_by_partial_link_text is deprecated. Please use find_elements(by=By.PARTIAL_LINK_TEXT, value=link_text) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.PARTIAL_LINK_TEXT, value=link_text)

def find_element_by_name(self, name) -> WebElement:
"""
Finds an element by name.
:Args:
- name: The name of the element to find.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_name('foo')
"""
warnings.warn(
"find_element_by_name is deprecated. Please use find_element(by=By.NAME, value=name) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.NAME, value=name)

def find_elements_by_name(self, name) -> List[WebElement]:
"""
Finds elements by name.
:Args:
- name: The name of the elements to find.
:Returns:
- list of webelement - a list with elements if any was found. an
empty list if not
:Usage:
::
elements = driver.find_elements_by_name('foo')
"""
warnings.warn(
"find_elements_by_name is deprecated. Please use find_elements(by=By.NAME, value=name)=By.NAME, value=name) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.NAME, value=name)

def find_element_by_tag_name(self, name) -> WebElement:
"""
Finds an element by tag name.
:Args:
- name - name of html tag (eg: h1, a, span)
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_tag_name('h1')
"""
warnings.warn(
"find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.TAG_NAME, value=name)

def find_elements_by_tag_name(self, name) -> List[WebElement]:
"""
Finds elements by tag name.
:Args:
- name - name of html tag (eg: h1, a, span)
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_tag_name('h1')
"""
warnings.warn(
"find_elements_by_tag_name is deprecated. Please use find_elements(by=By.TAG_NAME, value=name) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.TAG_NAME, value=name)

def find_element_by_class_name(self, name) -> WebElement:
"""
Finds an element by class name.
:Args:
- name: The class name of the element to find.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_class_name('foo')
"""
warnings.warn(
"find_element_by_class_name is deprecated. Please use find_element(by=By.CLASS_NAME, value=name) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.CLASS_NAME, value=name)

def find_elements_by_class_name(self, name) -> List[WebElement]:
"""
Finds elements by class name.
:Args:
- name: The class name of the elements to find.
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_class_name('foo')
"""
warnings.warn(
"find_elements_by_class_name is deprecated. Please use find_elements(by=By.CLASS_NAME, value=name) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.CLASS_NAME, value=name)

def find_element_by_css_selector(self, css_selector) -> WebElement:
"""
Finds an element by css selector.
:Args:
- css_selector - CSS selector string, ex: 'a.nav#home'
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_css_selector('#foo')
"""
warnings.warn(
"find_element_by_css_selector is deprecated. Please use find_element(by=By.CSS_SELECTOR, value=css_selector) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)

def find_elements_by_css_selector(self, css_selector) -> List[WebElement]:
"""
Finds elements by css selector.
:Args:
- css_selector - CSS selector string, ex: 'a.nav#home'
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_css_selector('.foo')
"""
warnings.warn(
"find_elements_by_css_selector is deprecated. Please use find_elements(by=By.CSS_SELECTOR, value=css_selector) instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_elements(by=By.CSS_SELECTOR, value=css_selector)

def pin_script(self, script, script_key=None) -> ScriptKey:
"""
Expand Down
Loading

0 comments on commit 4bbb7c2

Please sign in to comment.