In python using chromedriver, I quit Chrome processes with:
driver.close()
Could'nt you scrape in headless mode? (example for chrome)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.headless = True
...
driver = webdriver.Chrome(chrome_options = chrome_options)
driver.create_options()
Last Updated : 06 Mar, 2020
Syntax :
driver.close() driver.quit()
When you are finished with the browser session you should call quit, instead of close:,When you are finished with a window or tab and it is not the last window or tab open in your browser, you should close it and switch back to the window you were using previously. Assuming you followed the code sample in the previous section you will have the previous window handle stored in a variable. Put this together and you will get:,Windows and tabsGet window handleSwitching windows or tabsCreate new window (or) new tab and switchClosing a window or tabQuitting the browser at the end of a session,WebDriver does not make the distinction between windows and tabs. If your site opens a new tab or window, Selenium will let you work with it using a window handle. Each window has a unique identifier which remains persistent in a single session. You can get the window handle of the current window by using:
driver.getWindowHandle();
driver.current_window_handle
driver.CurrentWindowHandle;
driver.window_handle
await driver.getWindowHandle();
driver.windowHandle
If you have installed Selenium Python bindings, you can start using it from Python like this.,The python which you are running should have the selenium module installed.,Next, we are sending keys, this is similar to entering keys using your keyboard. Special keys can be send using Keys class imported from selenium.webdriver.common.keys:,To use the remote WebDriver, you should have Selenium server running. To run the server, use this command:
from selenium
import webdriver
from selenium.webdriver.common.keys
import Keys
from selenium.webdriver.common.by
import By
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element(By.NAME, "q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found."
not in driver.page_source
driver.close()
python python_org_search.py
from selenium
import webdriver
from selenium.webdriver.common.keys
import Keys
from selenium.webdriver.common.by
import By
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title