Al iniciar la función
def run(driver_path): driver = webdriver.Chrome(executable_path=driver_path) driver.get('https://tproger.ru/quiz/real-programmer/') button = driver.find_element_by_class_name("quiz_button") button.click() run(driver_path)Estoy recibiendo errores como estos:
<ipython-input-27-c5a7960e105f>:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(executable_path=driver_path) <ipython-input-27-c5a7960e105f>:10: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead button = driver.find_element_by_class_name("quiz_button")... pero no puedo entender por qué.
Estoy usando webdriver en la última versión para la versión de mi Chrome. no se por que me sale
`find_element_by_* commands are deprecated`... cuando está en la documentación que existe el comando.
@DebanjanB mencionó y explicó la nueva estructura, también es mejor usar estas líneas:
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.service import Service s = Service('C:/Users/.../chromedriver.exe') driver = webdriver.Chrome(service=s)Como mencionaron otros, debe usar find_element() o find_elements() en lugar de find_element_by_*() o find_elements_by_*() .
Escribí el patrón de expresiones regulares para reemplazar los métodos obsoletos por uno nuevo, así que intente esto si lo necesita.
# from - eg find_element_by_id("test") find_element(s?)_by_([az]+)\((.*) # to - eg find_element(By.ID, "test") find_element$1(By.\U$2\E, $3Nota: necesita la línea de importación para usar los nuevos métodos
from selenium.webdriver.common.by import By