0

trying to login instagram from chrome but its instantly closes the window here is the code

url = "https://www.instagram.com"
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import time
from bs4 import BeautifulSoup

driver = webdriver.Chrome()
driver.get(url)
driver.maximize_window
click_button = driver.find_element(value="a9-- _ap36 _a9_0")
click_button.click
time.sleep(2000)

2
  • What is the exception stack trace? Apart from the mentioned mistakes, I bet selenium cannot find the element and thus raises an exception .. which closes your application.
    – Jib
    Commented 10 hours ago
  • If it closes "instantly" then there must have been an exception other wise it would pause for 2000 seconds. Also, driver.maximize_window is effectively a noop
    – SIGHUP
    Commented 8 hours ago

1 Answer 1

0
  • Maximize Window: You need to call the maximize_window method correctly.

      # Maximize the browser window
      driver.maximize_window()
    
  • Element Selector: The find_element method should specify the By strategy.

      # Find the login button (update the selector as needed)
      click_button = driver.find_element(By.CLASS_NAME, "a9-- _ap36 _a9_0")
    
  • Click Method: You need to call the click method correctly.

      # Click the login button
      click_button.click()
    
New contributor
Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.