파이썬 셀레니움에서 execute_script 사용법 문의...
조회수 2484회
아래 코드에서 textarea의 문자열은 xpath를 사용해 엘리멘트를 추출해 body변수의 문자열을 해당 엘리멘트의 value에 할당하는 자바크립트 코드입니다.
그리고 drv.execute_script(textarea)로 실행시키려고 합니다.
제가 쓴 이 코드가 문법적으로 맞나요?
실제로 실행해보니 "selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token" 라는 에러메시지가
나옵니다.
어디에 문제가 있는 걸까요?
drv.execute_script는 하나의 명령문만 실행시킬 수 있는 건가요?
아니면 여러 개의 자바스크립트 명령문을 입력해도 실행되는 건가요?
textarea = 'function getElementByXpath(path) {\
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;}\n
getElementByXpath("//*[@id=\'smart_editor2_content\']/div[4]/textarea[1]").value = "' + body + '"'
drv.execute_script(textarea)
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력