1

I have using python selenium to do some test but I don't want it to open any browser, so how I can use a headless browser?? can you guys help me :(( Here is my code:

from selenium import webdriver
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome('/Users/toanhac/Downloads/chromedriver')


url = 'https://mail.google.com/mail/u/0/#inbox'
driver.get(url)

driver.implicitly_wait(15) 


driver.find_element_by_id("identifierId").send_keys(mail)
driver.find_element_by_id("identifierNext").click()

driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_id("passwordNext").click()

1 Answer 1

2

Just set headless to True:

from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True 

Full code:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True 

driver = webdriver.Chrome('/Users/toanhac/Downloads/chromedriver', options=options)


url = 'https://mail.google.com/mail/u/0/#inbox'
driver.get(url)

driver.implicitly_wait(15) 


driver.find_element_by_id("identifierId").send_keys(mail)
driver.find_element_by_id("identifierNext").click()

driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_id("passwordNext").click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.