Is it possible to create an action chain in selenium if one of the required elements will not exist until the action chain begins executing?
For example, I am trying to perform a drag and drop in selenium. The catch is that the target of the drop only exists while a drag is occurring. The intuitive solution for a drag and drop seems to be doing:
source = driver.find_element(...)
target = driver.find_element(...)
ActionChains(driver).drag_and_drop(source, target)
This will not work because target
does not exist until a drag has begun.
I have tried doing something along the lines of:
source = driver.find_element(...)
drag_and_drop = ActionChains(driver)
drag_and_drop.click_and_hold(source)
drag_and_drop.move_by_offset(10, 10)
drag_and_drop.perform()
target = driver.find_element(...)
drag_and_drop.move_to_element(target)
drag_and_drop.release()
drag_and_drop.perform()
This also does not work. It seems like the mouse is released after the first perform which would cause the target to disappear. This seems to indicate that a single action chain with a single perform()
call would be needed. I have tried researching to see if there is any way to lazily find an element when its step of the action chain is needed, but I could not find any way to do that.
Is there any way to achieve something like this in selenium?