강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

HyeonJoon Jeong님의 프로필 이미지
HyeonJoon Jeong

작성한 질문수

파이썬 입문 및 웹 크롤링을 활용한 다양한 자동화 어플리케이션 제작하기

NameError: name 'driver' is not defined 질문 드려요

작성

·

2.8K

0

site = "https://1.1.1.1/"

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs",{
    "download.default_directory":"C:\\ABCD\\temp"
})




def runTest():
    driver = webdriver.Chrome(executable_path='C:/Python/project/chromedriver',chrome_options=chrome_options)
    driver.get(site)
    ByPassSSLAuth()

def ByPassSSLAuth():    #인증서 오류 통과
    driver.find_element_by_xpath('//*[@id="details-button"]').click()
    driver.find_element_by_xpath('//*[@id="proceed-link"]').click()
    driver.implicitly_wait(5)

runTest()

위 코드들을 함수를 이용하지 않고 작성할 경우에는 정상적으로 작동이 됩니다.

그런데 함수에 넣어서 구동하려고 하면 NameError: name 'driver' is not defined 에러가 발생합니다.

함수를 이용해서 구현하고 싶은데 방법을 모르겠습니다.

답변 1

0

좋은사람님의 프로필 이미지
좋은사람
지식공유자

실행 순서가 문제가 있는 것 같습니다.

함수를 사용할 때 가장 먼저 초기화가 되도록 작성하셔야 해요.

HyeonJoon Jeong님의 프로필 이미지
HyeonJoon Jeong

작성한 질문수

질문하기