问题
So I am trying to select the current date, or use a system call from Powershell or Linux/Mac to a system variable with the OS Module. I need help in understanding the best way about how to go about accomplishing this.
- Option 1. How can I select the Highlighted date within the Calendar
- Option 2. How can I use a System Variable that will format the date to what I desire
Preferably I like option 2 because the system variable will always be set by that of the computer. So I know that the date is always what I need and is current.
Here is a picture.
Notice that today's highlighted portion is the 27th, which is today's date.
However, I am thinking a system variable might be able to just format the date to what I want.
In powershell I know the command is Get-Date -UFormat %D
. However, I would like to know how to pass this off, I also think the XPATH I have is wrong.
# Select Current Date
# Set Variable for OS_DATE to be in Format MM/DD/YYYY
# For Powershell $(Get-Date -UFormat %D)
# //*[@id='createdTo']/option[text()='01/27/2020']
#element = WebDriverWait(browser, 20).until(
# EC.element_to_be_clickable((By.XPATH,"//*[@id='createdTo']/option[text()='01/27/2020']")))
#element.click();
Does anyone have any suggestions? I am trying to input the date as always current in there, here is the source for the element that I need to update.
<input type="text" aria-labelledby="dateTo" class="form-control ng-pristine ng-isolate-scope ng-valid-date ng-not-empty ng-valid ng-valid-required ng-touched" datepicker-popup="MM/dd/yyyy" ng-model="dateTo" show-weeks="false" is-open="uploadedTo" placeholder="MM/DD/YYYY" ng-change="changeUploadDate();" ng-keydown="dateInputKeyDown($event,'uploadedTo')" required="" name="createdTo" id="createdTo" style="">
Also here is the source code on my Github Repository
I have been working on this a while now and have even taken some of the tips from the response I got from below. I finally figured out how to update the field. However, it is not overwriting the field. I am attaching the screenshot and the code that updates the field to showcase the overall issue.
Here is the code that got to input the date
element = WebDriverWait(browser, 20).until(
EC.element_to_be_clickable((By.XPATH,"//input[@id='createdTo']")))
element.send_keys(date);
Currently the code is commented out as the incorrect date prevents the file from downloading.
回答1:
So this actually works for printing the date after I set a variable from within the code.
element = WebDriverWait(browser, 20).until(
EC.element_to_be_clickable((By.XPATH,"//input[@id='createdTo']")))
element.send_keys(date);
The variable is obviously date, which is defined as
from datetime import date
# System Variables
today = date.today()
date = today.strftime("%m/%d/%Y")
来源:https://stackoverflow.com/questions/59935423/how-to-select-current-date-and-or-use-system-variables-or-system-calls-to-forwar