When using Selenium's click_and_hold method exactly what conditions or actions cause the mouse click to release? - selenium

I've had several occasions in my selenium tests where I decided to use Selenium's click_and_hold() (source code here) method on some element. The source code makes it look like it will stay pressed indefinitely but there are definitely some actions, such as a simple click, that cause the held click to be released. Obviously calling release will release the held click too, but does anyone have a grasp on exactly what actions/conditions (either from the script or the page itself) will cause the held click to be released?
I've linked to the documentation for the python bindings, but I assume this would be the same no matter what language is used to write the script. Please let me know if this assumption is incorrect!

release()
release(on_element) releases a held mouse button on an element. If on_element is None releases on current mouse position which is defined as:
def release(self, on_element=None):
"""
Releasing a held mouse button on an element.
:Args:
- on_element: The element to mouse up.
If None, releases on current mouse position.
"""
if on_element:
self.move_to_element(on_element)
if self._driver.w3c:
self.w3c_actions.pointer_action.release()
self.w3c_actions.key_action.pause()
else:
self._actions.append(lambda: self._driver.execute(Command.MOUSE_UP, {}))
return self
release() is invoked by default by different methods of the ActionChains implementation. Some of them are as follows:
release(): Releasing a held mouse button on an element.
drag_and_drop(source, target): Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button.
drag_and_drop_by_offset(source, xoffset, yoffset): Holds down the left mouse button on the source element, then moves to the target offset and releases the mouse button.
click_and_hold()
click_and_hold() holds down the left mouse button on an element.
So you saw it right, the source code confirms the same that it will stay pressed indefinitely unless release() is directly invoked or invoked through other methods. However there can be other actions / events which may cause the hold down left mouse button to be released implicitly. These actions / events can be a result of any of the HTML DOM Events. HTML DOM events allow JavaScript / AjaxCalls to register different event handlers on elements in an HTML document. Some of the mostly encountered events are:
HTML DOM UiEvent: Events that are triggered from the user interface belongs to the UiEvent Object.
onload Event: The onload event occurs when an object has been loaded.
onresize Event: The onresize event occurs when the browser window has been resized.
onscroll Event: The onscroll event occurs when an element's scrollbar is being scrolled.
HTML DOM FocusEvent: Events that occur when elements gets or loses focus, belongs to the FocusEvent Object.
onblur Event: The event occurs when an element loses focus
onfocus Event: The event occurs when an element gets focus
onfocusin Event: The event occurs when an element is about to get focus
onfocusout Event: The event occurs when an element is about to lose focus
The Event Object: All event objects in the DOM are based on the Event Object.
onchange Event: The onchange event occurs when the value of an element has been changed.
HTML DOM MouseEvent: Events that occur when the mouse interacts with the HTML document belongs to the MouseEvent Object.
onmousedown Event: The onmousedown event occurs when a user presses a mouse button over an element.
onmouseup Event: The onmouseup event occurs when a user releases a mouse button over an element.
HTML DOM DragEvent: Events that occur when elements are dragged and/or dropped, belongs to the DragEvent Object.
ondrag Event: The ondrag event occurs when an element or text selection is being dragged.
ondragstart Event: The ondragstart event occurs when the user starts to drag an element or text selection.
HTML DOM TransitionEvent: Events that occur when a CSS transition runs, belongs to the TransitionEvent Object.
transitionend Event: The event occurs when a CSS transition has completed
key_up()
The key_up() method also releases a modifier key. As an example:
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
This usecase
Without any visibility to your usecase of implementing click_and_hold() it is to be noted that, key_down() is a method which performs a modifier key press and it does not release the modifier key and subsequent interactions may assume it's kept pressed. Note that the modifier key is never released implicitly. Either key_up(theKey) or send_keys(Keys.NULL) must be called to release the modifier.

Generally any action that results in a mouse up event being called.
Click will call a mouse down event and then a mouse up event (As shown in the Code)
Click_and_hold() will only perform the mouse down part. If you then call anything else that triggers the mouse up event, the mouse click will be released.
Remember selenium is just passing a list of actions over to the driver binary that is controlling the browser using the JSON wire protocol. The commands you use in code are translated into JavaScript actions before being passed over the wire so the driver binary controlling the browser probably doesn't have much in the way of context of exactly what the original commands before they were broken down were.

Related

Can you cancel a drag programmatically

I am assuming, though I don't know for sure, that while a react-dnd drag is going on, it is possible for the handler of an async event [such as a setTimeout handler or the receipt handler of a websocket message] to get scheduled on the event loop. Please correct me if I am wrong and the event loop is not yielded while a drag is in progress.
If in fact the event loop can be yielded to async event handlers in the middle of a drag, and if it so happens that the event handler needs to mutate the drag source, how should this situation be resolved? Perhaps the mutation of the drag source in the middle of a drag is disallowed by the react-dnd framework. If such a mutation is allowed, confusion could ensue for the user.
A simple strategy to follow in such a case would be to cancel the drag and inform the user that a higher priority event needed to be taken care of that pre-empted the drag. Is it possible to cancel the drag programmatically in such cases?
Many thanks.
Azad

How do i prevent mouse and touch events from trigger for DisplayObjects below a backdrop

I have several display objects in createjs and event using easeljs i want to prevent from mouse and touch event passing through them.
i want like a easy one liner like .mouseEnabled or .mouseChildren is there something will will prevent any other interaction for the objcts below this. i can try adding all events to a backdrop movieclip which tint background color and prevent default and stopPropogation will that help?
so how to i prevent from any type of interaction taking place in canvas just by placing a displayobject that's like wall which will not allow the other displayobjects from getting click, mouseover or touch events.
You can add obj.mouseEnabled= obj.mouseChildren = false; to any you don't want to receive events.
If you just want to block events with a child on top, simply add a mouse handler to it.
cover.on("click", function(){});
You don't need stopPropagation, since that will only prevent events from bubbling in the current hierarchy (ie, surfacing an event to its direct parent). Events do not "pass through" objects that have mouse handlers on them.
Hope that helps!

Labview button freezes after pressed once

I'm trying to program something to read voltage from the Labview ULx library and add the voltage into an array. I tried to do so using an event structure while setting a boolean button 's mechanical action to "Latch when pressed". However, the "Latch when pressed" option seems doesn't work and the program reads the voltage and adds it to the array correctly and it freezes.
front panel
Block diagram:
When you use a Value Changed event with a latched Boolean control, you need to read the control's value inside the event structure in order to reset the latch.
Just move the Sample control's terminal inside the event structure, then it should work as you expect.
Tip: you are free to use the Latch When Pressed action if you want, but the standard action for UI buttons in the OS (Windows etc) is actually Latch When Released. You can check this by clicking on a button, dragging the mouse pointer off the button and then releasing it - the button shouldn't operate. You might want to decide which one makes more sense for your application.

Slow label and picturebox event firing which are child of Button

i have developed custom control which inherits Button control, actually i`m creating button with one picturebox and label on Button(picturebox and label are child controls). I created same method and wired child controls to behave as clicking on parent(Button), it works but its slow no mather what i do(tried with InvokeOnClick, me.performclick, Me.OnClick(New EventArgs()), tried with same method for all events), but clicking on label or picture box is slow, i need it to be fast as clicking directly on button cause in my application is very important to be able to click on button twice in second for example, if you click on label or picturebox twice at second it will fire just one time not 2.
What i have been thinking of is to make label and picturebox invisible for event is it possible or anyother idea ?
Thanks in forward
You are doing battle with ControlStyles.StandardDoubleClick. Which is turned on for the PictureBox and Label controls but turned off for Button.
So when you are clicking rapidly on either the picturebox or the label then they'll generate the DoubleClick event instead of the Click event. You'll interpret that as "slow" since you probably didn't write a handler for that event. Subscribing the event and calling Me.OnClick is a workaround.
Just don't do this. PictureBox and Label are point-and-click convenience controls but they are extraordinarily wasteful. It takes just two lines of code in the button's OnPaint() method override to get the exact same outcome, minus the overhead and the event problems. Use e.Graphics.DrawImage() to draw the pb's image and TextRenderer.DrawText() to draw the label's text.
Using MouseDown event ensures the event is triggered once per click, regardless of click/doubleclick.

TileControl.ItemClick event vs TileControl.ItemPress event

I'm trying to figure out what the difference of a click and a press event on a devexpress tile control is.
According to the online documentation:
TileControl.ItemClick Event Fires when an end-user clicks a TileItem
within the TileControl.
...
Remarks
Handle the ItemClick event to respond to an end-user clicking any item
within the current TileControl object. You can also use handle the
TileItem.ItemClick event to respond to clicking an individual
TileItem. This event can be raised in code via the
TileItem.PerformItemClick method. The TileItem.ItemClick event is
fired before the ItemClick event.
The ItemClick event comes after the ItemPress event when the left
mouse button is released. If an item is being dragged, the ItemClick
event is never fired.
' ' ' ' ' ' ' ' ' ' '
TileControl.ItemPress Event Fires when an end-user presses a TileItem within the current
TileControl.
...
Remarks
Tile items have two event types to respond to an end-user clicking
them at runtime: item press and item click events. Immediately after
an end-user clicks a tile item, tile item press events are fired.
First, the TileItem.ItemPress event is raised. After that, the
ItemPress event is fired.
This is probably very obvious to a more experienced developer but I'm very confused about this and don't understand when to use click/press. When should I use "ItemPress"?
in vb.net when a control is clicked, it means that you have fired two events, the mousedown and the mouseup event and i think, in your case, and as mentioned in the documentation, ItemClick Remark int last section:
The ItemClick event comes after the ItemPress event when the left
mouse button is released. If an item is being dragged, the
ItemClick event is never fired.
when you release the mouse left button after pressing it, and if you have not dragged the Tile Item an Itemclick event will be fired, else the ItemPress event will be pressed.