Home > Enterprise >  DepricationWarning when using Webdriver
DepricationWarning when using Webdriver

Time:12-15

When I run selenium, I sometimes get this depricationwarning which is really weird. The error message doesn't display alot of information about the warning. Is there a fix?

Error:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
main.py:15: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  driver.find_element_by_name("gameId").send_keys(gamepin Keys.ENTER)
main.py:16: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  driver.find_element_by_id("nickname").send_keys(username Keys.ENTER)
Traceback (most recent call last):
  File "main.py", line 16, in <module>
    driver.find_element_by_id("nickname").send_keys(username Keys.ENTER)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 472, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 1244, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="nickname"]"}
  (Session info: chrome=91.0.4472.101)
Stacktrace:
#0 0x55f607e05919 <unknown>

CodePudding user response:

Use the newer one since driver.find_element_by is depreciated.

driver.find_element(By.ID,"nickname").send_keys(username Keys.ENTER)

What I would recommended is using Webdriver waits if it's after page loading.

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID,"nickname"))).send_keys(username Keys.ENTER)

Import:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
  • Related