<p>在Centos上设置(以根用户身份进行所有安装)</p>
<p>安装pip下载<a href="https://bootstrap.pypa.io/get-pip.py" rel="nofollow noreferrer">https://bootstrap.pypa.io/get-pip.py</a></p>
<pre><code>python get-pip.py
</code></pre>
<p>安装selenium
如果您的系统上有pip,您可以简单地安装或升级Python绑定:
pip安装-U selenium</p>
<p>或者,您可以从PyPI(例如selenium-2.53.1.tar.gz)下载源发行版,将其取消归档,然后运行:</p>
<pre><code>python setup.py install
</code></pre>
<p>安装程序:pyvirtualdisplay</p>
<pre><code>pip install pyvirtualdisplay
yum install Xvfb libXfont Xorg
</code></pre>
<p>然后修改脚本,在**和**中添加粗体行</p>
<pre><code>**from pyvirtualdisplay import Display**
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class SeleniumDemo(unittest.TestCase):
def setUp(self):
**self.display = Display(visible=0, size=(800, 600))
self.display.start()**
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.soastastore.com/"
self.verificationErrors = []
self.accept_next_alert = True
def tearDown(self):`enter code here`
self.driver.quit()
***self.display.stop()***
self.assertEqual([], self.verificationErrors)
</code></pre>