1 year ago
#212671
swapna savalgi
Selenium_Webdriver_Python: Send_Keys (Keys + Keys.Enter ) is not working
I'm trying to send the keys by passing a variable inside it (var name : NextDayFormatted).Because it is a string and to avoid any future error I'm using the below code-
browser.find_element_by_css_selector("...").send_keys(NextDayFormatted + Keys.Enter)
Whenever I'm running this single line of code independently, it works fine. But, when I'm running all , it fails. It is passing the value that I have assigned to my variable (NextDayFormatted) but doesn't hit ENTER due to which the next line of code is failing.
PS: This issue persists in ENTER and RETURN both.
Can you please guide me on this?
Full code:
browser.get("url")
username = "abcd"
pwd = "def"
email = browser.find_element_by_name('email')
email.send_keys(username)
password = browser.find_element_by_name('password')
password.send_keys(pwd)
browser.find_element_by_tag_name('button').click()
#Click on filter icon
browser.find_element_by_xpath('....').click()
#Click Add filter
browser.find_element_by_xpath('....').click()
#Select the fields from the dropdown - Appointment Start Date & After
browser.find_element_by_xpath('....').click()
#The file needs to be extracted on every fridays therefore apply the appointment strt date logic in the search box.
Next_Date = datetime.datetime.today() + datetime.timedelta(days = 2)
Next_Date_Formatted = next_date.strftime('%m/%d/%Y')
#Applying the above variable in the search box
browser.find_element_by_css_selector('....').send_keys(Next_Date_Formatted + Keys.ENTER)`enter code here`
#Click on submit button
browser.find_element_by_css_selector('....').click()
python
selenium-webdriver
web-scraping
webdriver
sendkeys
0 Answers
Your Answer