셀레늄을 설치하고 대충 돌려 봤으니 이번에는 기본적인 기능부터 조져볼 것이다.
https://www.selenium.dev/documentation/webdriver/browser_manipulation/
현재 로드된 URL을 리턴한다.
currentUrl = driver.current_url
print(currentUrl)
# 결과
https://velog.io/@exoluse/series
F5를 눌러 새로고침 한것과 똑같은 효과를 낸다.
title 태그의 텍스트를 리턴한다.
title = driver.title
print(title)
# 결과
exoluse (exoluse) / 시리즈- velog
현재 띄우고 있는 창의 핸들러를 리턴한다.
currentWindow = driver.current_window_handle
print(currentWindow)
# 결과
CDwindow-C7B7F4ED7C2A1B0212ECC911092BEF5F
새로운 탭 또는 창을 띄울 수 있다.
# 탭 띄우기
driver.switch_to.new_window("tab")
# 창 띄우기
driver.switch_to.new_window("window")
프로세스상 열려있는 모든 윈도우 또는 탭을 리턴한다.
# 처음 window
currentUrl = driver.current_url
windowFirstLoaded = driver.window_handles[0]
# 두번째 window(tab)
driver.switch_to.new_window("tab")
windowSecondLoaded = driver.window_handles[1]
# 세번째 window
driver.switch_to.new_window("window")
windowThirdLoaded = driver.window_handles[2]
지정한 윈도우를 활성화 시킨다.
# 두번째 만든 window 로 이동해라
driver.switch_to.window(windowSecondLoaded)
현재 활성화 되어 있는 탭 또는 창을 닫을 수 있다.
# 창 닫기
driver.close()
같은 프로세스 상에서 움직이는 모든 탭과 창을 종료한다.
# 프로그램 종료
driver.quit()
아이프레임부터 다뤄 보겠다.
https://www.selenium.dev/documentation/webdriver/browser_manipulation/#frames-and-iframes