반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 네이버매물크롤링
- 네이버 로그인 캡챠해결
- pywinauto 윈도우
- 네이버 로그인 영수증 해결
- pywinauto 윈도우제어
- 파이썬 네이버 로그인
- Element is not clickable at point
- UiPath
- uipath 입문
- 날짜 정규식
- pycdas.exe
- 파이썬 가상환경 설치방법
- selenium
- 파이썬 가상환경 설치
- pywinauto
- vscode venv 설치
- venv 설치
- Uipath 기초
- Uipath 설치방법
- 네이버 로그인 하기
- 네이버부동산크롤링
- 네이버커머스API
- 왕초보 파이썬 실행
- Python
- Selenium 셀렉터잡기
- 파이썬 환경설정
- 가상환경설치
- 파이썬네이버부동산
- 커머스API
- pycdc.exe
Archives
- Today
- Total
콘솔워크
selenium webdriver 새 탭 간의 이동 본문
반응형
from selenium import webdriver
import time
# WebDriver 인스턴스 생성
driver = webdriver.Chrome()
# 탭 열기
driver.get("https://www.example.com")
example_tab = driver.window_handles[0]
time.sleep(1)
driver.execute_script("window.open('https://www.google.com');")
google_tab = driver.window_handles[1]
time.sleep(1)
driver.execute_script("window.open('https://www.yahoo.com');")
yahoo_tab = driver.window_handles[2]
time.sleep(1)
driver.switch_to.window(yahoo_tab)
driver.close()
time.sleep(1)
# 다시 첫 번째 탭으로 전환
driver.switch_to.window(google_tab)
driver.close()
time.sleep(1)
# WebDriver 종료
driver.quit()
항상 띄워놓아야 하는 탭을 변수로 지정해놓고 탭 이동을 하면 아주 편리하다.
반응형
'프로그래밍 > python' 카테고리의 다른 글
Python의 포함 연산자 in, not in (0) | 2023.07.03 |
---|---|
dict list를 key1을 기준으로 그룹화하고, 각 그룹에 속하는 key2들을 모으는 방법은 다음과 같습니다. (0) | 2023.06.26 |
python pyinstaller exe file decomplie 과정 (0) | 2023.06.23 |
현재 날짜를 기준으로 간편하게 다른 날짜를 구하는 법 (0) | 2023.06.22 |
파이썬 공백제외한 글자수 세기 (0) | 2023.06.21 |