Reputation: 2335
I made a method to click on the calendar field and then choose the date, but when I move the parameters, is returning error.
My method
def select_current_date(self, *locator1, *locator2):
self.driver.find_element(*locator1).click()
WebDriverWait(self.driver, AUTOCOMPLETE_TIMEOUT).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, ".ui-icon.ui-icon-circle-triangle-w")))
self.driver.find_element(*locator2).click()
WebDriverWait(self.driver, AUTOCOMPLETE_TIMEOUT).until(
EC.invisibility_of_element_located((By.CSS_SELECTOR, ".ui-datepicker-title")))
Passing the parameters
self.select_current_date(*EventsLocators.RECEIVED, *EventsLocators.CURRENT_DATE)
My error
E File "/Users/rafael/Desktop/projects/automated_tests/base.py", line 23
E def select_current_date(self, *locator1, *locator2):
E ^
E SyntaxError: invalid syntax
Any idea?
Cheers!
Upvotes: 0
Views: 85
Reputation: 51787
If you read the docs for your method you'll see:
find_element(by='id', value=None)
That means find_element
needs two parameters. I'm going to go out on a limb and guess that EventsLocators.RECEIVED
is a 2-element list or tuple. If it's not, then this won't work at all. But what you actually need to do is just remove the *
s from your function definition and function call:
def select_current_date(self, locator1, locator2):
self.driver.find_element(*locator1).click()
WebDriverWait(self.driver, AUTOCOMPLETE_TIMEOUT).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, ".ui-icon.ui-icon-circle-triangle-w")))
self.driver.find_element(*locator2).click()
WebDriverWait(self.driver, AUTOCOMPLETE_TIMEOUT).until(
EC.invisibility_of_element_located((By.CSS_SELECTOR, ".ui-datepicker-title")))
thing_one = ['by', 'value']
thing_two = ['replace', 'these things']
self.select_current_date(thing_one, thing_two)
I don't know the particulars of what you're passing in, but they must be some kind of iterable, otherwise your function signatures won't match.
Upvotes: 1
Reputation: 473763
You don't need (and actually you cannot do it this way) to unpack the arguments, replace:
def select_current_date(self, *locator1, *locator2):
with just:
def select_current_date(self, locator1, locator2):
When calling the method, now simply use:
self.select_current_date(EventsLocators.RECEIVED, EventsLocators.CURRENT_DATE)
Upvotes: 3