Home > Enterprise >  the page closes as soon as it opens using webdriver
the page closes as soon as it opens using webdriver

Time:01-05

enter image description here

code:

chrom_driver_pat = "C:\pythondriver\chromedriver"


driver = webdriver.Chrome(executable_path=chrom_driver_pat)


driver.get("https://instagram.com/")

terminal:


c:\Users\arda6\Desktop\pyhton_kursu\selenium\setup.py:7: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(executable_path=chrom_driver_pat)

DevTools listening on ws://127.0.0.1:56927/devtools/browser/7ce68db7-9314-4927-9718-ca24f43ec2e0

When I run the code here, the instagram site should open and stay open, but when I run it, the site closes as soon as it opens. What should I do?

the page closes as soon as it opens

CodePudding user response:

It shouldn't stay open with the code you've provided.

For example:

driver.get("https://instagram.com/")

Should be:

driver.get("https://instagram.com/"")

There is one more thing you should do to make sure it works:

from time import sleep
#your code
#here
sleep(15)

This will make sure the code doesn't stop working after it's done what you wanted it to do for another 15 seconds.

CodePudding user response:

If you want to keep the Chrome Tab alive after code execution. Consider to use Options.

from selenium.webdriver.chrome.options import Options
# Don't Close Chrome
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
# Initialize Chrome
driver = webdriver.Chrome(options=chrome_options)
  • Related