반응형
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
driver = webdriver.Chrome()
driver.get("https://www.w3schools.com/html/")
driver.maximize_window()
time.sleep(5)
# 특정 영역 스크롤
elem = driver.find_element_by_xpath('//*[@id="leftmenuinnerinner"]/a[62]')
# 방법 1 :ActionChain
#actions = ActionChains(driver) #드라이버를 ActionChains에 담는다
#actions.move_to_element(elem).perform() # 담은 actions의 move_to_element 메서드 함수를 사용
# find 함수로 찾은 특정영역을 넣어주고 마지막에 .perform()을 해준다.
# 방법 2:
#xy = elem.location_once_scrolled_into_view #함수가 아니니까 () 쓰지마세요. (변수임)
# 이것은 elem 가 위치한 좌표정보 (x,y) 값을 xy 변수에 담은 것이다.
# 그런데도 스크롤을 내리는 것과 같은 효과를 준다.
#print("type: ", type(xy)) #dict 형태로 출력
#print("value:", xy)
elem.click()
time.sleep(3)
driver.quit()
반응형