Fwd: Re: How to improve this code?
Hendrik van Rooyen
hendrik at microcorp.co.za
Wed Sep 16 13:48:05 CEST 2009
From a private email, forwarded to the list:
---------- Forwarded Message ----------
Subject: Re: How to improve this code?
Date: Tuesday 15 September 2009
From: Oltmans <rolf.oltmans at gmail.com>
To: hendrik at microcorp.co.za
On Sep 15, 1:13 pm, Hendrik van Rooyen <hend... at microcorp.co.za>
> (i) a True if All the elements in match are in aList, else False?
> (ii) a True if any one or more of the members of match are in aList?
> (iii) Something else?
That's a good question because I failed miserably in explaining my
problem clearly. My original question isn't what I'm trying to solve.
My apologies. I will try to explain here clearly. I'm using a 3rd-
party library named Selenium (used for web-automation) and it has a
method named is_element_present(ele) i.e. takes one element and return
true if it finds this element in the page's HTML and returns false
otherwise. Given this, I'm just trying to write a method
are_elements_present(aList) whose job is to return True if and only if
all elements in aList are present in page's HTML. So here is how
are_elements_present() looks like
if not eleLocators:
for ele in eleLocators:
print 'cannot find this element= '+str(ele)
Now suppose page HTML contains with these IDs ( ID is an attribute
like <input id="inp1" />) = div1,div2,div3,div4,div5,inp1,inp2
and if I call the above method this way are_elements_present
([div1,div2,inp1,inp2]) then it should return True. If I call like
are_elements_present([div1,div2,div10,inp1]) it should return False.
So I hope I've explained myself. Now all I'm looking for is to write
are_elements_presents() in a more Pythonic way. So please let me know
if I can write are_elements_present() in more smart/shorter way.
Thanks a lot for your help, in advance.
More information about the Python-list