Reputation: 1
I tried with below python code to select random date from calander
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
days = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10','11', '12', '13', '14', '15', '16', '17', '18', '19', '20','21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']
years = ['2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028']
When I am running the code, it is giving the error webelement is not iterable
.
Upvotes: 0
Views: 690
Reputation: 15204
random choice is probably what you are looking for:
from random import choice
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
days = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10','11', '12', '13', '14', '15', '16', '17', '18', '19', '20','21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']
years = ['2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028']
rand_date = '{}.{}.{}'.format(*map(choice, [days, months, years]))
Test runs:
29.May.2017
28.Feb.2023
10.Feb.2020
29.Jul.2023
4.Feb.2009
3.Jun.2019
22.Jul.2026
5.Apr.2012
7.Dec.2021
Upvotes: 2