I often build ActionChains to interact with MUI components. Here is one that enters the date MM/DD/YYYY
but ensures we start typing in the MM portion of the input. I have to wait for the animation of the field label to move out of the way before the input will accept anything.
actions = ActionChains(driver, duration=CHAIN_DURATION)
actions.move_to_element(element)
actions.click(element)
actions.pause(.25) # animation of label to move out of the way.
actions.send_keys(Keys.ARROW_LEFT)
actions.send_keys(Keys.ARROW_LEFT)
actions.send_keys(date_str)
actions.send_keys(Keys.TAB)
actions.perform()
The problem is this animation speed is variable (and it's not always known how fast each component will be). What I wish I had was the ability to perform a WebDriverWait.until(expected_condition)
in the middle of the ActionChain. In this case I would wait until the label element (different from the input element) has stopped moving.
Is this possible in some way?
I often build ActionChains to interact with MUI components. Here is one that enters the date MM/DD/YYYY
but ensures we start typing in the MM portion of the input. I have to wait for the animation of the field label to move out of the way before the input will accept anything.
actions = ActionChains(driver, duration=CHAIN_DURATION)
actions.move_to_element(element)
actions.click(element)
actions.pause(.25) # animation of label to move out of the way.
actions.send_keys(Keys.ARROW_LEFT)
actions.send_keys(Keys.ARROW_LEFT)
actions.send_keys(date_str)
actions.send_keys(Keys.TAB)
actions.perform()
The problem is this animation speed is variable (and it's not always known how fast each component will be). What I wish I had was the ability to perform a WebDriverWait.until(expected_condition)
in the middle of the ActionChain. In this case I would wait until the label element (different from the input element) has stopped moving.
Is this possible in some way?
Share Improve this question edited Mar 27 at 12:36 Olivier Tassinari 8,6916 gold badges25 silver badges28 bronze badges asked Mar 6 at 15:52 Marcel WilsonMarcel Wilson 4,5902 gold badges34 silver badges67 bronze badges 5 |2 Answers
Reset to default 1I found a sample page with a MUI date control, https://mui/x/react-date-pickers/date-range-picker. The code below works with it.
Basically I send the desired date to the INPUT until the placeholder text disappears.
import time
from selenium import webdriver
from selenium.webdrivermon.by import By
driver = webdriver.Chrome()
url = "https://mui/x/react-date-pickers/date-range-picker/"
driver.get(url)
target_date = "03072025"
date_field = driver.find_elements(By.CSS_SELECTOR, "input")[0]
date_field.click()
while date_field.get_attribute("value") == "MM/DD/YYYY":
date_field.send_keys(target_date)
time.sleep(0.1)
time.sleep(0.5) # additional wait may be needed?
date_field.clear()
date_field.send_keys(target_date)
driver.quit()
What you need to do is the following:
Find out the locator for input "MM/DD/YYYY" element using xpath, css or ID
Click on the element or its direct parent element
Use a while loop that checks for the DOM Property "value" of the element to change to MM/DD/YYYY and exit once it changes to it.
Then SendKeys or type each character slowly to the element
You do not need any arbitrary pauses, delays, sleeps or actions chain
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744964322a4603579.html
ElementNotInteractableException
(or whatever) to stop firing. Once it stops, you know the element is ready. – JeffC Commented Mar 6 at 17:29