我如何使用无头浏览器运行Selenium Python

时间:2020-10-29 03:17:42

标签: selenium google-chrome-headless

我已经使用python selenium进行了一些测试,但是我不希望它打开任何浏览器,所以如何使用无头浏览器?你们可以帮我吗:(( 这是我的代码:

Rscript

1 个答案:

答案 0 :(得分:1)

只需将headless设置为True

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

完整代码:

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()
相关问题