I'm writing a text in Selenium that gets the left-most column of a table and verifies that the strings in their cells match a list of dates I have. The code I have looks something like this:
dates = ["20130501", "20130502", "20130506", "20130507", "20130508", "20130509", "20130510", "20130513", "20130514", "20130515"]
mytable = self.driver.find_element(By.ID, "mytable")
datecells = mytable.find_elements(By.CSS_SELECTOR, "tbody td:first-child")
for date, cell in zip(dates, datecells):
print "'{0}', '{1}'".format(date, cell.text) # For debugging
#self.assertEqual(date, cell.text)
When the assert is left commented out, I get this printed out as a result:
'20130501', '' "20130502', '' '20130506', '' '20130507', '' '20130508', '' '20130509', '' '20130510', '' '20130513', '' '20130514', '' '20130515', ''
The weird thing is, if I put a breakpoint on the print (Using MyEclipse with PyDev), and look at cell in the variables tab of PyDev Debug before it's output, I can see the proper text, and the code outputs as expected:
'20130501', '20130501' '20130502', '20130502' '20130506', '20130506' '20130507', '20130507' '20130508', '20130508' '20130509', '20130509' '20130510', '20130510' '20130513', '20130513' '20130514', '20130514' '20130515', '20130515'
Is there some weird observer effect quirk of WebElement .text properties where it can only be properly evaluated by this debugger, or is there some condition I should be waiting for in order to get the proper values from the cells without having to step through?