[Python] Warning came out when I raised from Selenium 3 to 4 [Web Driver]

Introduction

In a survey to write Previously posted Selenium article, I raised Selenium on my private PC from 3 to 4, but along with that, a large amount of Selenium 3 logs that were regularly executed by cron Warning now appears.

Since it is a Warning, the code itself ends normally, but I do not want the log to be unnecessarily long, so I analyzed the source code of Selenium 4 and corrected my code and succeeded in erasing all Warnings, so I will note here I will leave.

DeprecationWarning: executable_path has been deprecated, please pass in a Service object In Selenium3, if the browser driver is not in the PATH, the driver was started as follows.

from selenium import webdriver

driver = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver")
driver.get('https://www.google.com/')

However, if you want to do the same with Selenium 4, you need to pass the executable_path to the Service object and then the Service object as shown below, instead of passing the executable_path directly when starting the driver.

from selenium import webdriver
from selenium.webdriver.firefox import service as fs

firefox_servie = fs.Service(executable_path="/usr/local/bin/geckodriver")
driver = webdriver.Firefox(service=firefox_servie)
driver.get('https://www.google.com/')

DeprecationWarning: service_log_path has been deprecated, please pass in a Service object When specifying the log output destination, the specification is to pass service_log_path to the Service object as well as executable_path. However, please be aware of the following two points.

** ① The name of the keyword will be log_path instead of service_log_path (2) It is necessary to pass executable_path to the Service object even if the browser driver is in the PATH. ** **

So in this case, the 4th line above is as follows.

firefox_servie = fs.Service(executable_path="/usr/local/bin/geckodriver", log_path='/my/log/path')

UserWarning: find_element_by_* commands are deprecated. Please use find_element() instead As you can see in the message, the function named find_element_by_ * is now deprecated, and the by_ * part is now specified by the keyword variable by offind_element ().

For example, suppose you have the following code for Selenium3: (It is assumed that the driver executable file is in the PATH)

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://www.google.com/')
element = driver.find_element_by_xpath("//input[@type='text']")
element.send_keys('Qiita')
element.submit()

If this is made into the Selenium 4 specification, it will be as follows.

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.get('https://www.google.com/')
element = driver.find_element(by=By.XPATH, value="//input[@type='text']")
element.send_keys('Qiita')
element.submit()

Summary

Rewriting find_element is quite troublesome, so if you have a lot of test code, it seems to be difficult unless you automate it as if you were writing a script.

Recommended Posts

[Python] Warning came out when I raised from Selenium 3 to 4 [Web Driver]
What I did when updating from Python 2.6 to 2.7
I want to use jar from python
A story I was addicted to when inserting from Python to a PostgreSQL table
How to open a web browser from python
I tried web scraping using python and selenium
[Python] I want to manage 7DaysToDie from Discord! 1/3
[2021 version] From Selenium Basic installation to Web scraping execution by Python Windows 10 (64bit)
[Python] Flow from web scraping to data analysis
I want to use ceres solver from python
[Python] I want to manage 7DaysToDie from Discord! 2/3
I want to make C ++ code from Python code!
Automatic login to ServiceNow with Selenium Web Driver
I raised the Python version from 2 to 3, but every time I restart the ubuntu terminal, the version remains 2.
When I tried to introduce python3 to atom, I got stuck
I wanted to use the Python library from MATLAB
Python --Notes when converting from str type to int type
I was addicted to scraping with Selenium (+ Python) in 2020
[Python3] I want to generate harassment names from Japanese!
How to download files from Selenium in Python in Chrome
What I was addicted to when using Python tornado
I want to do something in Python when I finish
Changes from Python 3.0 to Python 3.5
Python web scraping selenium
[Selenium] I want to display the browser by hitting the driver on the host OS from WSL
I dare to fill out the form without using selenium
[Python] I started Poetry & Impression that I moved from Pipenv to poetry
I want to start a lot of processes from python
[Python] Introduction to scraping | Program to open web pages (selenium webdriver)
I want to automatically attend online classes with Python + Selenium!
What I was addicted to when migrating Processing users to Python
I want to send a message from Python to LINE Bot
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Operate your browser using the Selenium Web Driver Python bindings
[Python3] List of sites that I referred to when I started Python
I made you to execute a command from a web browser
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
Post from Python to Slack
Cheating from PHP to Python
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Start to Selenium using python
Web scraping using Selenium (Python)
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Things to watch out for when using default arguments in Python
A memorandum when I tried to get it automatically with selenium
What I was addicted to when introducing ALE to Vim for Python
Things to note when running Python on EC2 from AWS Lambda
How to avoid duplication of data when inputting from Python to SQLite.
I want to run the Python GUI when starting Raspberry Pi
I tried to make a periodical process with Selenium and Python
I tried to find out if ReDoS is possible with Python
What to do if Insecure Platform Warning appears when running Python
I read "Reinforcement Learning with Python: From Introduction to Practice" Chapter 1
I wrote a script to extract a web page link in Python
What I did when I wanted to make Python faster -Numba edition-
I tried to cut out a still image from the video
How to automatically install Chrome Driver for Chrome version with Python + Selenium + Chrome
I read "Reinforcement Learning with Python: From Introduction to Practice" Chapter 2
I want to pass an argument to a python function and execute it from PHP on a web server