为禁用右键单击的日期字段查找 XPATH - Selenium Python

Finding XPATH for a date field where the right click is disabled - Selenium Python

我试图在下面的 URL 中找到 DOB 字段的 xpath。我可以单击日历,但单击后,右键单击被禁用。所以我使用 javascript 执行器来解析日期值,如下所示

URL

element = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='date']")))
self.driver.execute_script("arguments[0].value = arguments[1]", element, "2004-03-18")

解析后,日期 2004 年 3 月 18 日已成功填充到应用程序网页中,但由于错误(“格式不正确”),我仍然无法单击“下一步”。我已经检查过了,除非我点击日历并 Click/Press 输入,否则它不会工作。

我尝试使用以下代码点击后按回车键。但它有一个错误“TypeError:'str' object is not callable”

 a = self.driver.find_element(By.XPATH, configReader.readConfig("locators", locator)).click()
 b = Keys.ENTER

我的目标如下

1:Parse the date using java script executor
2:Click the date icon using xpath = //input[@type='date']
3:Press Enter

在单击“下一步”按钮之前,您需要填写所有必填字段。否则将被禁用。

代码:

driver.maximize_window()

wait = WebDriverWait(driver, 30)


driver.get("https://diy.iiflinsurance.com/form/proposer-form?quote_id=Mr6ynrRUPktQJ8bHk1ix")

wait = WebDriverWait(driver, 30)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[placeholder='Full Name']"))).send_keys('Apratim Chaudhuri')
dob = wait.until(EC.visibility_of_element_located((By.XPATH, "//input[@type='date']")))

driver.execute_script("arguments[0].value = arguments[1]", dob, "2004-03-18")

wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Male']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Email Id']"))).send_keys('ApratimChaudhuri@gmail.com')


wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Mobile Number']"))).send_keys('9789898989')
wait.until(EC.element_to_be_clickable((By.XPATH, "(//input[@placeholder='Mobile Number'])[2]"))).send_keys('9789898912')
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='NEXT']"))).click()

进口:

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

尝试触发一个事件,有时 Angular / React 站点有必要:

self.driver.execute_script("""
  let [input, date] = arguments
  input.value = date
  input.dispatchEvent(new Event('input', { bubbles: true }))
""", element, "2004-03-18")