Hi Skupin,
Please check the attachments for
1) the overview of the use case with alert action (overview_of_the_use_case_with_alert_action.png)
2) the detailed view of the client system with two users (detailed_view_of_the_client_system_with_two_users)
Overview
> User#1 is supposed to do any one of the below actions in order to interact with the Browser#1.
1. Tap
2. Double Tap
3. Scroll Up/Down and Right/Left
4. Pinch-Zoom in/out
> In parallel with User#1, User#2 wants to view the same page (which is currently displayed on the Browser#1) in the Browser#2 without interacting with it. This Browser#2 screen is for viewing purposes only.
So the goal here is, we need to bring the same page content in Browser#2 although there is no user interaction in it.
Solution
1. First, the client application will capture the touch coordinates and action type once the user is done with their action on the browser touch screen.
Assume, both users get context menu on their screen after a long press. User#1 can select the menu items by tapping it directly. But what about User#2' screen??? The same action must be done here somehow. So, when a user clicks an item from the context menu, the client application will fetch the touch coordinates (abs_x, abs_y) and the action type (say, single tap).
2. Then this info will be sent to the host application network.
3. The host application will receive the data, form the web driver commands and send it to the browser in the following way (consider the above scenario mentioned in #1, action type is single tap on the context menu' items with abs_x, abs_y coordinates):
3.1. First we need to check whether the click is intended for window elements / context menu items / alerts.
How to pre-validate if the context menu/alert is active?
For the context menu, it is possible by reading the state.
with driver1.using_context("chrome"):
cm_el = driver1.find_element(By.ID, "contentAreaContextMenu")
return cm_el.get_property("state")
For alerts, by reading the text (you mentioned this point in previous mail).
alert = driver1.switch_to_alert()
text = alert.text
3.2. If it is on the context menu, we have to convert the window' absolute coordinates to relative coordinates w.r.t context menu origin. Thus, we can target the same location of the browser page where the user is touched on the Browser#1. Then will send the click action like below using the relative coordinates.
As you know, the origin of the context menu can be retrieved by using "WebDriver:GetElementRect" command. By doing the calculation below, we will get the relative coordinates.
rel_x = abs_x - cm_x;
rel_y = abs_y - cm_y;
where,
abs_x, abs_y - window' absolute coordinates sent by client application.
cm_x, cm_y - origin coordinates of the context menu w.r.t the viewport.
rel_x, rel_y - relative coordinates w.r.t context menu origin.
The pointer events sequence is formed like below,
cm_el = driver1.find_element(By.ID, "contentAreaContextMenu")
touchHandler.pointer_move(rel_x, rel_y, origin=cm_el).pointer_down(0).pause(1500).pointer_up(0).perform()
The above scenario is for the context menu. Now I have to handle the alerts as well. As I mentioned the logic in 3.2, I need a way of getting coordinates of alerts since we cant use the window coordinates directly inside the alert (If I'm wrong here, please correct me).
Now I hope you are clear on why I'm not using the Alert' methods. I need to either accept/dismiss the alert using the received coordinates (Please note, the host application is unaware of the buttons the received coordinates point to, so I couldn't make use of accept() and dismiss() methods directly.)
If any point is not clear, please let me know.
Regards,
Rajapriya