파이썬 selenium ActionChains 기실행 동작 반복 오류
조회수 1726회
(목표) 네이버지도 자동차거리 소요시간 계산
현재 주소 입력 및 검색기능까지 진행하였으나, 오류가 발생하여 질문 드립니다.
셀레니움 ActoinChains를 여러번 사용하고 있습니다.
action.reset_actions를 사용하여 각 액션을 초기화하고 있으나,
액션 초기화가 되지 않고 이전 내용을 반복 합니다.
또한 주소 입력 후 엔터버튼을 실행하는 명령문에서 주소 입력까지만 실행되고,
엔터버튼은 action.reset_actions 명령문에서 실행됩니다.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
driver = webdriver.Chrome()
webdriver.Chrome()에 경로를 넣어야하지만, 경로가 현재 경로와 동일하므로 생략
driver.get('https://map.naver.com/v5/directions/-/-/-/carc=14070528.1667352,4364176.3814983,6,0,0,0,dh')
action = ActionChains(driver)
start = driver.find_element_by_xpath('//*[@id="directionStart0"]')
end = driver.find_element_by_xpath('//*[@id="directionGoal1"]')
search = driver.find_element_by_xpath('//*[@id="container"]/shrinkable-layout/div/directions-layout/directions-result/div/directions-search/div[2]/button[3]')
action.move_to_element(start).send_keys('서울 강남구 영동대로513').key_down(Keys.ENTER).perform()
action.reset_actions()
action.move_to_element(end).click().send_keys('서울 서초구 서초동 산144-4').key_down(Keys.ENTER).perform()
action.reset_actions()
action.move_to_element(search).click().perform()
action.reset_actions()
아래 코드를 넣으면 해결된다는 이야기가 있어 시도해보았으나 실패하였습니다.
def reset_actions(self):
"""
Clears actions that are already stored on the remote end.
Clears actions that are already stored locally and on the remote end
"""
if self._driver.w3c:
self._driver.execute(Command.W3C_CLEAR_ACTIONS)
else:
self._actions = []
self.w3c_actions.clear_actions()
self._actions = []
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
저도 똑같이 초기화가 안되는데 일단 임시 방편으로 action = ActionChains(driver)로 action을 다시 선언해주면 초기화가 되긴합니다;;
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력