Converting getCSS Count Code from java to python

Duncan Booth duncan.booth at invalid.invalid
Wed Feb 2 16:03:31 CET 2011


Stefan Behnel <stefan_ml at behnel.de> wrote:

> You are using Selenium RC here. I have no idea if there is a Python
> API to it or what that API looks like. The rest is just trivial code
> that you can map 1:1 to Python:
> 
>      def count_css_matches(css_locator):
>          java_script_code = '''
>              var cssMatches = eval_css("%s", window.document);
>              cssMatches.length;''' % css_locator
>          return int(selenium.getEval(java_script_code))
> 
> Although I'd simplify the JavaScript code somewhat to make it a plain 
> expression.

You also need somewhere:

    from selenium import selenium

and in Python the method that is needed is selenium.get_eval(...)

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list