Do headless web browser need selenium WebDriver?

后端 未结 2 880
忘掉有多难
忘掉有多难 2020-12-22 12:45

I am trying to use headless web browser(such as headless chrome) for our selenium tests.Should I have to use selenium WebDriver(for python or c# bindings)?

2条回答
  •  隐瞒了意图╮
    2020-12-22 13:46

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    import os

    Before we set up a Chrome web driver instance, we have to create an Options object that allows us to specify how exactly we want to launch Chrome. Let’s tell it that we want the browser to launch headless and that the window size should be set to 1920x1080. We also need ChromeDriver to be able to run Chrome at all 

    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--window-size=1920x1080")
    
    # download the chrome driver from https://sites.google.com/a/chromium.org/chromedriver/downloads and put it in the
    # current directory
    chrome_driver = os.getcwd() +"\\chromedriver.exe"
    
    driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
    driver.get("https://www.google.com")

提交回复
热议问题