- 전체
- Python 일반
- Python 수학
- Python 그래픽
- Python 자료구조
- Python 인공지능
- Python 인터넷
- Python SAGE
- wxPython
- TkInter
- iPython
- wxPython
- pyQT
- Jython
- django
- flask
- blender python scripting
- python for minecraft
- Python 데이터 분석
- Python RPA
- cython
- PyCharm
- pySide
Python 인터넷 [python 인터넷] How to Select CheckBox and Radio Button in Selenium WebDriver
2021.11.26 21:42
[python 인터넷] How to Select CheckBox and Radio Button in Selenium WebDriver
[Question]
When starting the function
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)
I'm getting errors as:
<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")
But cant understand why.
Using webdriver the latest version for my chrome's version. And I why
`find_element_by_* commands are deprecated`
if in the documentation the command exists
[Answer]
This error message...
DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
...implies that the find_element_by_*
commands are deprecated in the latest Selenium Python libraries.
As @AutomatedTester mentions: This DeprecationWarning was the reflection of the changes made with respect to the decision to simplify the APIs across the languages and this does that.
Solution
Instead you have to use find_element()
. As an example:
-
Using
class_name
:button = driver.find_element_by_class_name("quiz_button")
Needs be replaced with:
button = driver.find_element(By.CLASS_NAME, "quiz_button")
In similar lines you also have to change the following:
-
Using
id
:element = find_element_by_id("element_id")
Needs be replaced with:
element = driver.find_element(By.ID, "element_id")
-
Using
name
:element = find_element_by_name("element_name")
Needs be replaced with:
element = driver.find_element(By.NAME, "element_name")
-
Using
link_text
:element = find_element_by_link_text("element_link_text")
Needs be replaced with:
element = driver.find_element(By.LINK_TEXT, "element_link_text")
-
Using
partial_link_text
:element = find_element_by_partial_link_text("element_partial_link_text")
Needs be replaced with:
element = driver.find_element(By.PARTIAL_LINK_TEXT, "element_partial_link_text")
-
Using
tag_name
:element = find_element_by_tag_name("element_tag_name")
Needs be replaced with:
element = driver.find_element(By.TAG_NAME, "element_tag_name")
-
Using
css_selector
:element = find_element_by_css_selector("element_css_selector")
Needs be replaced with:
element = driver.find_element(By.CSS_SELECTOR, "element_css_selector")
-
Using
xpath
:element = find_element_by_xpath("element_xpath")
Needs be replaced with:
element = driver.find_element(By.XPATH, "element_xpath")
[출처] https://stackoverflow.com/questions/69875125/find-element-by-commands-are-deprecated-in-selenium/69875984
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.