Issue
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://youtube.com")
After I run this code, window appears, but it disappears 3 or 4 seconds later.
In others' computer, the window doesn't get closed. Is there anything wrong in my code? Then how can I solve this? Thank you.
Solution
After I run this code, window appears, but it disappears 3 or 4 seconds later.
When you say the above, my assumption is that code launches chrome browser, opens YouTube website and then it closes the browser without any errors. Is that true? If yes, then that is an expected behaviour in Python Selenium.
When the browser
object has reached the last line of code, it terminates itself closing the browser.
If you want the browser to remain open, then you need to detach the browser and driver using the detach
arguments in ChromeOptions
. See the code below:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(options=chrome_options)
browser.get("http://youtube.com")
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.