Converting getCSS Count Code from java to python

Stefan Behnel stefan_ml at behnel.de
Fri Feb 18 06:51:00 CET 2011


SMERSH009, 17.02.2011 22:46:
> am still stuck with the following error when I try to
> print self.count_css_matches('css=[id="listGuests"]')
> I've also included the Selenium code below. Any further help would be
> appreciated.
>
> Traceback (most recent call last):
>    File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line
> 27, in test_untitled
>      print self.count_css_matches('css=[id="listGuests"]')
>    File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line
> 17, in count_css_matches
>      return int(selenium.get_eval(self, java_script_code))
> TypeError: unbound method get_eval() must be called with selenium
> instance as first argument (got Untitled instance instead)
>
> ----------------------------------------------------------------------
>
>
> from selenium import selenium
> import unittest, time
> from datetime import datetime
>
> class Untitled(unittest.TestCase):
>      def count_css_matches(self, css_locator):
>          java_script_code = '''
>              var cssMatches = eval_css("%s", window.document);
>              cssMatches.length;''' % css_locator
>          return int(selenium.get_eval(self, java_script_code))
>          #return int(selenium.getEval(java_script_code))

You want to use "self.selenium" here, not "selenium".

Stefan


>      def setUp(self):
>          self.verificationErrors = []
>          self.selenium = selenium("localhost", 4445, "*chrome", "http://
> www.guestlistnation.com/")
>          self.selenium.start()
>
>
>
>      def test_untitled(self):
>          sel = self.selenium
>          sel.window_maximize()
>          sel.open("/Events.aspx?Location=SAN FRANCISCO")
>
> sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']")
>          sel.wait_for_page_to_load("30000")
>
>          print self.count_css_matches('css=[id="listGuests"]')
>
> if __name__ == "__main__":
>      unittest.main()
>
>





More information about the Python-list mailing list