久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何通過 Python 使用 Selenium 將日期作為文本直接

How to send a date directly as text to a calendar control with readonly attribute using Selenium through Python?(如何通過 Python 使用 Selenium 將日期作為文本直接發送到具有只讀屬性的日歷控件?) - IT屋-程序員軟件
本文介紹了如何通過 Python 使用 Selenium 將日期作為文本直接發送到具有只讀屬性的日歷控件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 python 和 selenium 從日歷中選擇一個日期,但我需要一些幫助,我在 VBA 中執行此操作,但我想在 python 中執行此操作.提前致謝.

I'm trying to select a date form a calendar with python and selenium but I need some help, I did this in VBA but I want to do this in python. Thanks in advance.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver=webdriver.Firefox(executable_path=r'..geckodriver.exe')
driver.get('https://burghquayregistrationoffice.inis.gov.ie/Website/AMSREG/AMSRegWeb.nsf/AppSelect?OpenForm')    

# this is the problem
driver.find_element_by_id('GNIBExDT').send_keys(10/08/2019)

推薦答案

這是一個只讀輸入 - 如果你查看 HTML src,它有 readonly 屬性.這意味著 send_keys 正在嘗試 鍵入你的價值,但不能,因為它是只讀的.但是,您仍然可以手動設置 - 嘗試:

It's a read-only input - if you look in the HTML src, it's got the readonly attribute. This means that send_keys, which works by emulating key presses as if it were a real user (to also trigger any eventlisteners listening for change in the input), is trying to type your value, but can't, since it's read-only. However, you can still set it manually - try:

driver.execute_script("document.getElementById('GNIBExDT').value = '10/08/2019'")

這會執行以下JS代碼:

This executes the following JS code:

document.getElementById('GNIBExDT') // Equivalent of driver.find_element_by_id('GNIBExDT') in pure JS
    .value = // Used to set the 'value' of the input, which is what will be read on the backend when the form is submitted. This just sets the value directly, so it doesn't matter if it's read-only.
    '10/08/2019' // The date, in string form.

他們似乎只是在示例網站上使用基本字符串來表示日期,因為它是一個自定義日期選擇器.因此,他們沒有做任何特別的事情,例如使用實際的日期格式或 Date 對象.但是,由于根據標題,這是您想要的,我將舉一個例子,讓其他在谷歌上搜索過這個問題的人這樣做:

It seems like they're just using basic strings on the example website to represent dates, since it's a custom datepicker. So, they're not doing anything special, such as using actual date formats or Date objects. However, since based on the title this is what you'd like, I'll give an example to do such for anyone else who's Googled this problem:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver=webdriver.Firefox(executable_path=r'..geckodriver.exe')
driver.get('https://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_date')

driver.execute_script("document.getElementsByTagName('input')[0]"  # Get the date picker from the DOM
                     +".valueAsDate"  # Set the value *as a date object* - this is only available in real date pickers (`<input type='date'>`)
                     +" = new Date('2020-03-11')"  # We therefore need to define it as a date object, which we do in 'yyyy-mm-dd hh:mm:ss GMT+hhmm' format
)

這篇關于如何通過 Python 使用 Selenium 將日期作為文本直接發送到具有只讀屬性的日歷控件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 亚洲视频在线观看 | 久久精品国产v日韩v亚洲 | 日本天堂视频在线观看 | 五月婷婷丁香婷婷 | 99久久婷婷国产亚洲终合精品 | 视频在线观看一区 | 精品成人| 欧美全黄 | 精品一区二区av | 欧美一区二区三区四区视频 | 欧美激情视频一区二区三区在线播放 | caoporn免费| 精品久久久久久 | 九九在线精品视频 | 一区久久 | 日韩精品久久一区二区三区 | 精品一区二区av | 99久久精品免费看国产高清 | 久久专区 | 成人亚洲综合 | 6996成人影院网在线播放 | 99久久精品国产毛片 | 成人精品毛片国产亚洲av十九禁 | 国产精品中文 | 羞羞的视频免费在线观看 | www.亚洲一区二区 | 日韩伦理一区二区 | 成人在线视频免费播放 | 日韩a v在线免费观看 | 国产一区二区不卡 | 毛片网站免费观看 | av中文网 | 天天射天天操天天干 | 国产成人jvid在线播放 | 成人网视频 | 91精品国产一二三 | 日韩欧美一区二区三区免费观看 | 国产午夜精品久久久 | 欧美日韩电影免费观看 | 日韩欧美国产精品一区 | 欧美成人一级视频 |