
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Make Firefox Headless Programmatically in Selenium with Python
We can make firefox headless programmatically in Selenium. This can be done with the help of the FirefoxOptions class. We shall then create an object option for that class.
We shall set the parameter options.headless to True value. This information of the browser has to be passed to the driver object. We have to add the import statement: from selenium.webdriver.firefox.options import Options as FirefoxOptions for FirefoxOptions class.
Syntax
options = webdriver.FirefoxOptions() options.headless = True
Example
Code Implementation.
from selenium import webdriver from selenium.webdriver.firefox.options import Options as FirefoxOptions #object of FirefoxOptions options = webdriver.FirefoxOptions() #set options.headless to True options.headless = True driver = webdriver. Firefox(executable_path="C:\geckodriver.exe", options=options) driver.implicitly_wait(0.4) driver.get("https://www.tutorialspoint.com/index.htm") #identify element m = driver.find_element_by_xpath("//*[text()='Library']") driver.execute_script("arguments[0].click();",m) print("Page title after click: " + driver.title) driver.quit()
Output
Advertisements