TypeError: The 'str' object is not callable when you try to click & ldquo; Datepicker & rdquo;

advertisements

The relevant HTML

<div id="datepickerbox" class="ym-gbox-left">
 <div class="datepick_label">
  <div id="datepicker" class="hasDatepicker">
   <div class="ui-datepicker-inline ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="display: block;">

My code

self.driver.find_element(By.XPATH('//*[@id="datepicker"]')).click()
dateWidget = self.driver.find_element(By.ID("ui-datepicker-div"))
rows = dateWidget.find_element_by_tag_name("tr")
columns = dateWidget.find_element_by_tag_name("td")
for cell in columns: self.driver.findElement(By.LINK_TEXT("20")).click()

The error I'm getting

self.driver.find_element(By.XPATH('//*[@id="datepicker"]')).click()
TypeError: 'str' object is not callable

How can I make this work?


If you want to use the generic find_element() method - pass two arguments - the By locator type and the locator value:

self.driver.find_element(By.XPATH, '//*[@id="datepicker"]')

Though, it would be cleaner to use the specific find_element_by_xpath() method:

self.driver.find_element_by_xpath('//*[@id="datepicker"]')

And, even cleaner in this case would be to use "by id" locator:

self.driver.find_element_by_id("datepicker")