Selenium

[Selenium] 크롬 창 종료 현상?

MASSO 2023. 6. 16. 01:01
728x90

쭉 주피터 노트북 쓰다가 파이참을 한 번 설치해봤는데,
버전 문제인지 스크립트 실행하면 크롬 창이 바로 꺼지는 현상 발생;
 
뭐가 문제인가 하고 구글링 해본 끝에
https://github.com/SeleniumHQ/selenium/issues/10188

[🐛 Bug]: Selenium closes after script runs · Issue #10188 · SeleniumHQ/selenium

What happened? When ever I try to open a website using driver.get(url) it just closes. I've read some things in stack overflow that say to use chrome_options.add_experimental_option("detach", True)...

github.com

이런 글을 발견, 답변대로 option 부분 추가 및
기존 driver = webdriver.Chrome()으로 작성했던 부분을
driver = webdriver.Chrome(options=chrome_options)으로 바꿔주니 정상 작동했다.
 

import selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

import time

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options)
url = "http://www.e-himart.co.kr/"
driver.get(url)
#time.sleep(5)

* 테스트를 위해 time.sleep(5)는 주석 처리
 

더보기

+

이전에 VS로 할 때도 꺼져서 input() 넣고 해결한 거 기억나서 파이참에도 input() 넣어봤는데

import selenium
import pyperclip
from selenium import webdriver
#from selenium.webdriver.chrome.service import Service
#from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

#chrome_options = Options()
#chrome_options.add_experimental_option("detach", True)
#driver = webdriver.Chrome(options=chrome_options)
driver = webdriver.Chrome()
driver.maximize_window()
url = "http://www.e-himart.co.kr/"
driver.get(url)
time.sleep(5)

driver.find_element(By.XPATH,'//*[@id="header"]/div[3]/div/div[2]/div/div/ul/li[3]/a').click()

input()

얘도 되더라....... 하하

 

728x90

'Selenium' 카테고리의 다른 글

[Selenium] 스크린샷  (0) 2023.10.10
[Selenium] 실험1  (0) 2023.09.09
[Selenium] 엑셀 파일 읽기/쓰기  (0) 2023.01.21
[Selenium] 뮤트하기  (0) 2023.01.08
[Selenium] 값 비교  (0) 2023.01.05