我正在尝试创建一个用于运行selenium python命令的sublime文本插件。这是我的代码......
import sublime
import sublime_plugin
try:
import unittest2 as unittest
except ImportError:
import unittest
from selenium import webdriver
def run_tests(view):
browser = webdriver.Firefox()
browser.quit()
class RunSeleniumCommand(sublime_plugin.TextCommand):
def run(self, edit):
run_tests(self.view)
一旦我保存插件脚本,这就会给我一个错误。
reloading plugin RunSelenium.runselenium
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 72, in reload_plugin
m = imp.reload(m)
File "./imp.py", line 276, in reload
File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1022, in load_module
File "<frozen importlib._bootstrap>", line 1003, in load_module
File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 868, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "/Users/user/Library/Application Support/Sublime Text 3/Packages/RunSelenium/runselenium.py", line 9, in <module>
from selenium import webdriver
ImportError: No module named 'selenium'
普通的selenium(用python编写)脚本运行正常。 我在这里缺少什么?
答案 0 :(得分:3)
好的,我检查了sys.path
变量中是否存在硒的安装位置。我添加了它,这解决了问题。
import sublime
import sublime_plugin
import sys
try:
import unittest2 as unittest
except ImportError:
import unittest
sys.path.append("/Library/Python/2.7/site-packages")
from selenium import webdriver
def run_tests(view):
browser = webdriver.Firefox()
browser.quit()
class RunSeleniumCommand(sublime_plugin.TextCommand):
def run(self, edit):
run_tests(self.view)