2017-11-26 2 views
1

비교적 쉬운 질문이 있지만 어디서나 답변을 찾을 수없는 것 같습니다. Selenium Chrome 웹 드라이버를 사용하여 Windows Form을 닫으면 Windows Form/Application을 닫지 만 Chrome 콘솔과 브라우저는 열어 둡니다. driver.Quit() 또는 .Close();를 사용하는 방법이 있나요? 양식이 닫힐 때? 아래 예제와 같은 것.Windows에서 Chrome 웹 드라이버 닫기 양식 닫음

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
    { 
     driver.Quit(); 
    } 

답변

0

다음을 시도해보십시오.

driver.Quit(); 
driver = null; 
+0

나를 위해 작동하지 않았습니다. 그래도 감사합니다 –

0

닫기 버튼을 누르면 양식 닫기 이벤트가 중단되지 않는 것이 문제입니다.

FormClosing 이벤트를 구독하고 드라이버에서 Quit 메서드를 호출해야합니다.

public Form1() 
    { 
     // (...) 
     this.FormClosing += this.Form1_FormClosing; 
    } 

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
    { 
     driver.Quit(); 
     Environment.Exit(0); 
    } 

F5 키를 사용하여 응용 프로그램을 실행할 때 드라이버 콘솔이 닫히지 만 Ctrl F5 키로 실행할 때는 닫히지 않습니다.