I am trying to create a sublime text plugin for running selenium python commands. Here is my code...
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)
This gives me an error as soon as I save the plugin script.
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'
Normal selenium (written in python) scripts run fine. What am I missing here?
Okay I checked if the installed location of selenium was there in sys.path
variable. I added it and that solves the problem.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.