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

0 votes
May 27, 2019 in Selenium by Fatima
1,054 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, 2019 by Anvi
• 14,010 points

Related Questions In Selenium

0 votes
1 answer
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
12,172 views
0 votes
1 answer
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,510 points
1,827 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

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

answered May 8, 2019 in Selenium by Anvi
• 14,010 points
479 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,510 points
1,845 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,870 points
1,635 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, 2019 in Selenium by Anvi
• 14,010 points
97 views