[BangPypers] Howto run python selenium script on remote server

Saju M sajuptpm at gmail.com
Thu Sep 29 10:56:24 CEST 2011


Hi,
I created a script using selenium and its working in my local system.
But when i trying to run it in remote machine (Centos), getting error.
This script should need to open a firefox browser. So i think the the
script could not open the firefox browser on remote machine(Server).
Have any way to run it on remote machine(Server)?????.


Traceback (most recent call last):
  File "script.py", line 34, in <module>
    s = Search()
  File "script.py", line 8, in __init__
    self.driver  = webdriver.Firefox()
  File "/home/madfishe/env6/lib/python2.6/site-packages/selenium-2.7.0-py2.6.egg/selenium/webdriver/firefox/webdriver.py",
line 46, in __init__
    self.binary, timeout),
  File "/home/madfishe/env6/lib/python2.6/site-packages/selenium-2.7.0-py2.6.egg/selenium/webdriver/firefox/extension_connection.py",
line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/home/madfishe/env6/lib/python2.6/site-packages/selenium-2.7.0-py2.6.egg/selenium/webdriver/firefox/firefox_binary.py",
line 44, in launch_browser
    self._wait_until_connectable()
  File "/home/madfishe/env6/lib/python2.6/site-packages/selenium-2.7.0-py2.6.egg/selenium/webdriver/firefox/firefox_binary.py",
line 87, in _wait_until_connectable
    raise WebDriverException("Can't load the profile. Profile Dir :
%s" % self.profile.path)
selenium.common.exceptions.WebDriverException: Message: "Can't load
the profile. Profile Dir : /tmp/tmpWmkFsy"

------------------------------------- script

from selenium import webdriver
import BeautifulSoup
class Search:
	def __init__(self):
		self.url ='http://www.google.co.in'
		self.search_url = None
		self.driver  = webdriver.Firefox()

	def search(self, search_query, search_location=None):
		if search_query:
			self.search_url = "%s/search?q=%s" %(self.url, search_query)
			self.driver.get(self.search_url)
			search_fld = self.driver.find_element_by_id("lst-ib")
			#help(search_fld)
			search_btn = self.driver.find_element_by_name("btnK")
			search_btn.submit()
			if search_location:
				self.change_location(search_location)
			html = self.driver.page_source
			soup=BeautifulSoup.BeautifulSoup(html)
			result = soup.findAll(attrs={"class" : "l"})
			return result

	def change_location(self, new_location):
		self.driver.find_element_by_id("toggle_location_link").click()
		self.driver.find_element_by_id("lc-input").send_keys(new_location)
		els = self.driver.find_elements_by_tag_name("input")
		set_el = [el for el in els if el.get_attribute('value')=='Set']
		#print "-------value-----", set_el[0].get_attribute('value')
		set_el[0].submit()
s = Search()
print"------search result------", s.search('python', 'kerala')


More information about the BangPypers mailing list