tips:仅在debian 9.0上做过测试
1. 下载可供调试的chrome版本
wget 'https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip'
- 解压zip:
unzip chromedriver_linux64.zip
2. 生成软连接
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
3. 安装python依赖
sudo apt-get install libxss1 libappindicator1 libindicator7
sudo apt-get install python-pip
sudo apt-get -y install xvfb gtk2-engines-pixbuf
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
sudo apt-get -y install imagemagick x11-apps
4.更改pip源
- 修改pip配置文件(没有壯陽藥
该文件则手动创建):
vim .pip/pip.conf
,在配置文件中加入以下内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
5.安装selenium
sudo pip install selenium
sudo pip install requests
6.编写测试文件查看是否安装成功
- 编写一个自动登录到ltcs,选中所有机器,并启动所有ltcs模块,并截图的Python脚本
#coding:utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
driver.get("http://172.19.143.20")
#ver.find_element_by_id('signin-container').click()
# LOGIN
driver.find_element_by_id('name').clear()
driver.find_element_by_id('name').send_keys('ltcs')
driver.find_element_by_id('password').clear()
driver.find_element_by_id('password').send_keys('rocky')#password
driver.find_element_by_id('enter').click()
# 禁用所有可信验证模块状态
driver.find_element_by_id('all_hosts').click()
driver.find_elements_by_class_name('btn-alt')[1].click()
t = driver.switch_to_alert()
print t.text
t.accept()
driver.save_screenshot("1.png")
driver.find_element_by_id('all_hosts').click()
driver.find_elements_by_class_name('btn-alt')[2].click()
t = driver.switch_to_alert()
print t.text
t.accept()
driver.save_screenshot(driver.title+".png")