简体   繁体   中英

How to Overwrite a Specific Field with Pre-existing Entry in Selenium with Python

So I am trying to overwrite a date field that I have to insert the current date so the data pull is always current. I currently have found the solution that overwrites the date field with Selenium Webdriver for Chrome and Python. However, the issue is that the date doesn't overwrite what is saved with the query. Here is the current code that sends the date.

# Select Current Date !!!NOTE ISSUE ON CURRENT DATE BEING SET!!!
# 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,"//input[@id='createdTo']")))
element.send_keys(date);

You can see the full code here Here is a picture that showcases what I need: 在此处输入图片说明

Notice the To fields above the calendar. I need to write the current date by overwriting the date that is loaded with the query. The current code writes out the date as follows: 在此处输入图片说明

If you needs some more context there was another question I had asked in order to figure out how to send the current date to that field. We came up with the above code as mentioned. However, it doesn't overwrite the current loaded data. More context can be found with the following link .

Following the suggestion by @supputuri worked.

# Click Calendar Icon
# Element XPATH = //*[@id='collapseFour-1']/div/fieldset/import-date-select/div[1]/div[3]/div/span/button/i
element = WebDriverWait(browser, 20).until(
                        EC.element_to_be_clickable((By.XPATH, "//*[@id='collapseFour-1']/div/fieldset/import-date-select/div[1]/div[3]/div/span/button/i")))
element.click();

# Click Today Button on Calendar
# Element XPATH = //*[@id='collapseFour-1']/div/fieldset/import-date-select/div[1]/div[3]/div/ul/li[2]/span/button[1]
element = WebDriverWait(browser, 20).until(
                                EC.element_to_be_clickable((By.XPATH, "//*[@id='collapseFour-1']/div/fieldset/import-date-select/div[1]/div[3]/div/ul/li[2]/span/button[1]")))
element.click();

In essence, all I had to do was click on the Today Button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM