How to send a date directly as text to a calendar control with readonly attribute using Selenium through Python?

后端 未结 2 1134
暖寄归人
暖寄归人 2021-01-21 18:27

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.



        
2条回答
  •  不要未来只要你来
    2021-01-21 19:10

    The field associated with the Date of Birth is having the attribute readonly. So to invoke send_keys() you have to:

    • Scroll to bring the element within the viewport.
    • Use execute_script() to remove the readonly attribute.
    • Invoke send_keys() to send the date.
    • You can use the following solution:

      • Code Block:

        from selenium import webdriver
        from selenium.webdriver.support.ui import WebDriverWait
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as EC
        
        driver.get("https://burghquayregistrationoffice.inis.gov.ie/Website/AMSREG/AMSRegWeb.nsf/AppSelect?OpenForm")
        dob = driver.find_element_by_css_selector("input#DOB")
        driver.execute_script("window.scrollBy(0, 400)")
        driver.execute_script("arguments[0].removeAttribute('readonly')", dob);
        driver.find_element_by_css_selector("input#DOB").send_keys("10/08/2019")
        
    • Browser Snapshot:

提交回复
热议问题