Is it possible to run headless browser using Python-Selenium?

0 votes
May 27 in Selenium by Fatima
74 views

1 answer to this question.

0 votes

Hi Fatima, you can run headless browser using Python-Selenium with following lines of code:

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys

opts = Options()
opts.set_headless()
assert opts.headless  # Operating in headless mode
browser = Firefox(executable_path=r"C:\Users\Anvi_R\Downloads\geckodriver-v0.24.0-win64\geckodriver.exe", options=opts)
browser.implicitly_wait(3)
browser.get('https://duckduckgo.com')

search_form = browser.find_element_by_id('search_form_input_homepage')
search_form.send_keys('real python')
search_form.submit()

results = browser.find_elements_by_id('links')
print(results[0].text)
answered May 27 by Anvi
• 12,860 points

Related Questions In Selenium

0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer

Selenium ChromeDriver issue - Want to run it in background, but not as headless browser

This is a flaw with ChromeDriver. Tried ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,090 points
968 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8 in Selenium by Anvi
• 12,860 points
146 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
592 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
901 views
0 votes
1 answer
0 votes
1 answer

Is it possible to do Database testing by using Selenium Webdriver?

Hey Kanika, Selenium Webdriver is limited to Testing Browser ...READ MORE

answered May 15 in Selenium by Anvi
• 12,860 points
57 views