from selenium.webdriver.chrome.options import Options
from selenium import webdriver
# 無界面模式
def ChromeDriverNOBrowser():
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driverChrome = webdriver.Chrome(executable_path="E:\\chromedriver",chrome_options=chrome_options)
return driverChrome
# 有界面的就簡單了
def ChromeDriverBrowser():
driverChrome = webdriver.Chrome(executable_path="E:\\chromedriver")
return driverChrome
用 headless 的 firefox
from selenium.webdriver.firefox.options import Options
ff_option = Options()
ff_option.add_argument('-headless')
firefox和chrome都可以設置無界面模式。
我一般在調試腳步的時候,可以使用有界面的模式,這樣可以看到元素定位的步驟。有時候用chrome打開項目時,需要定位的元素是排在li[0]的位置,但是selenium調用chrome打開,該元素排序就出現變化,至今未明白;所以只能在調試的時候,用有界面的模式看清楚元素定位的情況;
調試好后,加入了HTMLTestRunner,就可以用無界面的來跑,只看報告就行了
