I am using Python with Selenium Webdriver I have got the value of a textfield which is 1,000.000 I am using an if statement to check if the value from the textfield = 1,000.000 If Yes then pass else i use send_keys and enter 1,000.000 into the text field.
I am getting the following error: TypeError: cannot concatenate 'str' and 'WebElement' objects
Error
Traceback (most recent call last):
File "C:\Webdriver\reverted to backup\ClearCore 501\TestCases\DataPreviewsPage_TestCase.py", line 93, in test_add_DataPreviews
dp.is_maxrecords_1000_displayed()
File "C:\Webdriver\reverted to backup\ClearCore 501\Pages\data_previews.py", line 76, in is_maxrecords_1000_displayed
print "max_records_textfield does not have default value 1,000.00 The value is = " + max_records_textfield
TypeError: cannot concatenate 'str' and 'WebElement' objects
My code snippet is:
max records textfield has the value 1,000.000 as default
def is_maxrecords_1000_displayed(self):
max_records_textfield = self.driver.find_element(*MainPageLocators.datapreviews_maxrecords_textfield2)
print "max_records_textfield = ", max_records_textfield.get_attribute('value')
if max_records_textfield.get_attribute('value') == "1,000.000":
print "max_records_textfield" + max_records_textfield.get_attribute('value')
else:
print "max_records_textfield does not have default value 1,000.00 The value is = " + max_records_textfield
print "Going to enter 1,000.00 into the textfield"
max_records_textfield.send_keys("1,000.00")
Do i need to cast the webelement (max_records_textfield) to a string variable? How would i do this?
max_records_textfield.get_attribute('value'), instead of theWebElement-print "max_records_textfield does not have default value 1,000.00 The value is = " + max_records_textfield.get_attribute('value')