[Selenium] select box, check box, radio button 조작하기
요새 웹크롤링에 관심이 있는 SIR 회원님들이 많이 계신 것 같아서 글을 남깁니다 ^^
Selenium에서 select box, check box 및 radio button를 조작하는 방법은
비슷하면서도 조금 다른 점이 있습니다.
1. Check box & Radio button
클릭 메서드를 사용합니다.
[code]
driver.find_element_by_id("체크박스ID").click()
driver.find_element_by_id("라디오버튼ID").click()
[/code]
2. Select box
Select 함수를 사용합니다.
[code]
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_xpath('셀렉트박스XPATH'))
select.select_by_value('선택할 값')
[/code]
그럼 좋은 주말 되세요 ^^
댓글 1개
맘바멘탈리티
3년 전
좋은글 감사합니다. 한참 파이썬쪽 공부하고 있는데 셀레니움 라이브러리가 조금 업데이트 된것 같습니다. (Upgrade to Selenium 4)
셀레니움 업데이트된 import 를 해주던지
Select(driver.find_element_by_xpath('셀렉트박스XPATH'))
→
Select(driver.find_element(By.XPATH, '셀렉트박스XPATH''))
이렇게 바꾸니 정상적으로 오류없이 됩니다.
저처럼 안되시는분은 참고하세요~
https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/
셀레니움 업데이트된 import 를 해주던지
Select(driver.find_element_by_xpath('셀렉트박스XPATH'))
→
Select(driver.find_element(By.XPATH, '셀렉트박스XPATH''))
이렇게 바꾸니 정상적으로 오류없이 됩니다.
저처럼 안되시는분은 참고하세요~
https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2615 | ||
| 4945 | node.js | 6년 전 | 2388 | ||
| 4944 | node.js | 6년 전 | 2525 | ||
| 4943 | node.js | 6년 전 | 2276 | ||
| 4942 | node.js | 6년 전 | 2258 | ||
| 4941 | node.js | 6년 전 | 2723 | ||
| 4940 | node.js | 6년 전 | 1869 | ||
| 4939 | node.js | 6년 전 | 1997 | ||
| 4938 | node.js | 6년 전 | 2461 | ||
| 4937 | node.js | 6년 전 | 2253 | ||
| 4936 | node.js | 6년 전 | 2327 | ||
| 4935 | node.js | 6년 전 | 2139 | ||
| 4934 | node.js | 6년 전 | 2452 | ||
| 4933 | node.js | 6년 전 | 2251 | ||
| 4932 | node.js | 6년 전 | 2691 | ||
| 4931 | node.js | 6년 전 | 2076 | ||
| 4930 | node.js | 6년 전 | 2002 | ||
| 4929 | node.js | 6년 전 | 8638 | ||
| 4928 | node.js | 6년 전 | 3756 | ||
| 4927 | node.js | 6년 전 | 2399 | ||
| 4926 | node.js | 6년 전 | 2508 | ||
| 4925 | node.js | 6년 전 | 2092 | ||
| 4924 | node.js | 6년 전 | 3377 | ||
| 4923 | node.js | 6년 전 | 2227 | ||
| 4922 | node.js | 6년 전 | 1995 | ||
| 4921 | node.js | 6년 전 | 2050 | ||
| 4920 | node.js | 6년 전 | 1769 | ||
| 4919 | node.js | 6년 전 | 2038 | ||
| 4918 | node.js | 6년 전 | 2184 | ||
| 4917 | node.js | 6년 전 | 2399 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기