I have an IF-AND statement that isn't operating properly. This is occurring on Python 2.7.9.
numberOfActiveConfigs = len(driver.find_elements_by_xpath("//select[@id='active_config']/option"))
for cnt in range (0, 5):
print "Count: ", cnt
temp = len(driver.find_elements_by_xpath("//select[@id='active_config']/option"))
print type(numberOfActiveConfigs)
if numberOfActiveConfigs > 3:
cnt = cnt + 1
else:
numberOfActiveConfigs = temp
cnt = 0
print "Number of Configs: ", numberOfActiveConfigs
Basically, the code stores the number of elements in a table & then checks to see if the number of elements is greater than 3. If it is, then it increments count until it reaches '5' and stops. The print statements are for debugging.
For some reason, the 'if' statement keeps coming back as TRUE despite the fact that the count is equal to '2'.
Print out:
Count: 0
<type 'int'>
Count: 1
<type 'int'>
Count: 2
<type 'int'>
Count: 3
<type 'int'>
Count: 4
<type 'int'>
Number of Configs: 2
As you can also see, value 'numberOfActiveConfigs' is of type 'int', so this isn't a case where I'm comparing a string to an int. I have no clue why this is happening & have a feeling this is going to be a silly mistake on my behalf.
numberOfActiveConfigs
is set outside of yourfor
loop. You are always comparing the same value to see if it's> 3