I am trying to find the xpath for the DOB field in the following URL. I can click the calendar but after clicking, the right-click is disabled. SO I have used javascript executor to parse the date value like below
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")
Here after parsing, the date 18th march, 2004 is getting populated successfully in the application webpage but still I am not able to click "Next" due to the error("format not correct"). I have checked that until and unless I click the calendar and Click/Press Enter, its not going to work.
I have tried to press Enter after clicking using the below code. But its having an error "TypeError: 'str' object is not callable"
a = self.driver.find_element(By.XPATH, configReader.readConfig("locators", locator)).click()
b = Keys.ENTER
My target is the following
1:Parse the date using java script executor
2:Click the date icon using xpath = //input[@type='date']
3:Press Enter
CodePudding user response:
You need to fill all the mandatory fields before you click on the Next button. Otherwise it will be disabled.
Code:
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('[email protected]')
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()
Imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
CodePudding user response:
Try firing an event, sometimes it's necessary with Angular / React sites:
self.driver.execute_script("""
let [input, date] = arguments
input.value = date
input.dispatchEvent(new Event('input', { bubbles: true }))
""", element, "2004-03-18")