自动化测试中,web页面的用例一般会用selenium+Chrome Headless方式在Linux上运行,那么需要对Chrome进行以下的设置:

import time

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

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome('/usr/local/bin/chromedriver', options=chrome_options)
driver.get('http://www.google.com/');
print('open google')
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('tiaaaaaaaaaaa')
search_box.submit()
time.sleep(5) # Let the user actually see something!
print(driver.title)
driver.quit()

 

posted on 2021-04-01 14:16  forwill  阅读(675)  评论(0编辑  收藏  举报