简体   繁体   English

如何使用 Python 在 Selenium 中使用预先存在的条目覆盖特定字段

[英]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.我目前找到了使用 Chrome 和 Python 的 Selenium Webdriver 覆盖日期字段的解决方案。 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.按照@supputuri 的建议工作。

# 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.从本质上讲,我所要做的就是单击“今天”按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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