SoFunction
Updated on 2024-10-30

Python crawler Selenium implementation of the closing browser

Preface: WebDriver provides two methods to close the browser, one is the front to use the quit() method, the other is the close() method

  • close(): Close the current window.
  • quit(): close all windows
  • quit() is to close all windows, but not too much to say, test close()
from selenium import webdriver
from  import Keys
import time

driver = ()
("")

(2) #Sleep for two seconds and see the effect

driver.find_element_by_link_text('Login').click()

(2) #Sleep for two seconds and see the effect

driver.find_element_by_link_text("Register Now").click()

(2) #Sleep for two seconds and see the effect

# Get the current window handle
sreach_windows = driver.current_window_handle

# Get handles to all currently open windows
all_handles = driver.window_handles
for handle in all_handles:
 driver.switch_to.window(handle)
 ()
 (2)

Selenium Anthology Portal:

caption synopsis
Python Crawler - Selenium (1) Installation and Simple Use Detailed description of Selenium's dependencies on Windows and Centos7 installation and simple use of the environment
Python Crawler - Selenium (2) element positioning and WebDriver common methods Detailed introduction to the 8 ways to locate an element and use it in conjunction with methods such as click and type, submit, get assertion information, etc.
Python Crawler - Selenium (3) Common Ways to Control Your Browser Detailed introduction to the use of customizing the browser window size or full screen, controlling the browser backward, forward, refresh the browser and other methods
Python Crawler - Selenium (4) Configuring Startup Item Parameters Detailed description of Selenium startup parameters configuration, including no interface mode, browser window size settings, browser User-Agent (request header) and so on.
Python Crawler - Selenium (5) Mouse Events Detailed introduction to the use of mouse right-click, double-click, drag, mouse hover and other methods
Python Crawler - Selenium (6) Keyboard Events Detailed introduction to keyboard operation, including almost all commonly used keys and key combinations
Python Crawler - Selenium (7) Multi-Window Switching Detailed description of how Selenium realizes the freedom to switch between different windows
Python Crawler - Selenium (8) frame/iframe form nested pages Details on how to switch from the currently positioned body to a frame/iframe form in an inline page
Python Crawler - Selenium (9) Warning Box (Popup) Handling Details on how to locate and handle multiple types of warning pop-ups
Python Crawler - Selenium (10) Dropdown Box Processing Details on how to flexibly position and handle drop-down boxes
Python Crawler - Selenium (11) File Uploads Details how to elegantly specify files to upload via send_keys()
Python Crawler - Selenium (12) Getting Login Cookies and Adding Cookies to Automate Login Details on how to get cookies and use them for automatic login
Python Crawler - Selenium (13) Setting Up Element Waiting Details on how to elegantly set the element wait time to prevent the program from running too fast and causing the element positioning failure
Python Crawler - Selenium (14) Window Screenshots Detailed instructions on how to use window screenshots
Python Crawler - Selenium (15) Close Browser Detailed description of the difference between the two types of closing windows

to this article on the Python crawler Selenium to close the browser article is introduced to this, more related Selenium close the browser content please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!