24.06.01 17:29 작성
·
165
0
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
service = Service(executable_path=ChromeDriverManager().install())
webdriver.Chrome(service=service, options=chrome_options)
chrome_options.add_experimental_option("excludeSwitches",["enable-logging"])
driver = webdriver.Chrome()
driver.get('https://nid.naver.com/nidlogin.login?svctype=262144')
driver.maximize_window()
id = driver.find_element(By.CSS_SELECTOR, "#id")
id.send_keys("제 네이버 아이디 입니당")
ㅜㅜ자꾸 크롬창이 꺼지는데 어떻게 해야할까요
좋은 강의 항상 감사합니다! ;)
답변 1
1
안녕하세요, 인프런 AI 인턴입니다. sellytop2님, 문제 해결을 위해 도움을 드리겠습니다.
코드를 살펴보면 webdriver.Chrome()
이 두 번 호출되고 있어서 문제가 발생할 가능성이 있습니다. 첫 번째는 옵션을 포함하여 웹드라이버를 초기화 하고, 두 번째는 옵션 없이 새로운 웹드라이버 인스턴스를 생성하고 있습니다. 이로 인해 첫 번째로 생성된 브라우저 창이 바로 닫히게 될 수 있습니다.
또한, chrome_options.add_experimental_option("excludeSwitches",["enable-logging"])
코드가 webdriver.Chrome(service=service, options=chrome_options)
호출 이후에 있어서 실제로 적용되지 않고 있습니다. 이 옵션은 웹드라이버를 초기화하기 전에 설정되어야 합니다.
코드를 수정하기 위해서는 다음과 같이 조정하시면 됩니다:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
service = Service(executable_path=ChromeDriverManager().install())
# WebDriver 초기화 시 옵션을 넣어줍니다.
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get('https://nid.naver.com/nidlogin.login?svctype=262144')
driver.maximize_window()
id = driver.find_element(By.CSS_SELECTOR, "#id")
id.send_keys("제 네이버 아이디 입니당")
이렇게 수정하면, 설정한 옵션들이 제대로 적용되어 실행 중인 크롬 창이 닫히지 않을 것입니다. 문제가 계속된다면 추가적인 설정이나 다른 문제점을 확인해야 할 수도 있습니다. 도움이 되셨길 바랍니다!