Python Selenium: Show Tooltip on Mouse Pointer (Three.js/React/Canvas) - python

So this is a bit of a tricky situation. Using Three.js/ReactJS and canvas.
Scenario: When I click and drag a sphere beyond its boundaries a tooltip will show a warning message over the mouse pointer. When I release the mouse the tooltip will disappear. When I click and drag the sphere back to a position inside the boundaries, the tooltip will not be displayed once inside the boundaries.
Bear in mind this is tied into the state of the app handled by react, and in this instance the tooltip is being updated when the conditions are met and updated in the state.
The tooltip element is present however, the attributes and content gets updated on a click and hold when the sphere is out of bounds...
using
ActionChains(page.driver).move_to_element_with_offset(sphere_order_panel, -1047, 398).click_and_hold().move_to_element_with_offset(sphere_order_panel, -1633, 265).click_and_hold().perform()
clicks on the element and drags it to the position outside of its boundaries, but the tooltip is NOT updated... i've put a breakpoint on the page once i manually click into the page, my sphere gets snapped to my mouse location (meaning click_and_hold is indeed working... but i check the html and verify that the tooltip is not updated. however if i manually use my mouse and click on the sphere the tooltip will update! is selenium automation not executing the click_and_hold correctly? I don't think this is the case.
Is there a way to add the mouse pointer to the page using selenium?
Or is there a way to use execute_script() to use javascript on the page to satisfy my conditions to get the tooltip to be updated?
I'm really stuck on this.. and this is a tricky situation (for me at least)
Any help greatly appreciated.

to get around my issue, I had to do this
chain = ActionChains(page.driver).move_to_element_with_offset(sphere_order_panel, -1047, 398).click_and_hold()
chain = chain.move_to_element_with_offset(sphere_order_panel, -1047, 398)
chain.perform()

Related

Modify Tooltips in Pygal

I am creating an interactive World Map, where you can hover over different countries to see which one you are hovering over, and click them to link to a seperate HTML page with info on them. The problem is, when I hover over smaller countries like Switzerland, the tooltip itself covers the entire hitbox of the country, and I am not able to click on it.
I have already asked about moving the Tooltip elsewhere, or providing a link on the tooltip itself, but got no answers for those questions. So now I am asking; is it possible to completely hide a tooltip in pygal maps? Or perhaps change it to a toggle that activates on click? Or perhaps even render the tooltip relative to the cursor instead of relative to the Datapoint itself? My code is so close to being finished but is being held back by this rather infuriating issue.
Please let me know if I should also provide my code that I have for this issue.

how to simulate mouse hover in robot framework on a desktop application

Can anyone please let me know how to simulate mouse hover event using robot framework on a desktop application. I.e if I mouse hover on a specific item or an object, the sub menus are listed and i need to select one of the submenu item.
It depends on the automation library that you are using to interact with the Desktop application.
The normal approach is the following:
Find the element that you want to hover on (By ID or some other unique locator)
Get the attribute position of the element (X,Y)
Move your mouse to that position.
In this way you donĀ“t "hardcode" the x,y position what will make your test case flaky.

How to get tootip(infotip) text in python? (a popup text box appearing when a mouse cursor is hovered on)

I am currently working for an automatic screen capture program in Python3. While developing it, I ran into a couple of issues on Windows tooltip(infotip) boxes.
What I need to do is this:
1. First I need to find out whether there is any tooltip(infotip - a small text box appearing when a mouse cursor is hovered on an icon or a button) at a specified mouse coordinates. (e.g.) When a mouse cursor is moved to (300, 300) in the main monitor and hovered for a while, does a tooltip box appear? I hope I can get the result with a boolean variable if possible.
2. (main problem) If there is a tooltip, how can I get the content(text) in it?
I have tried solving the problems using pywinauto module, but as there is not much documentation about it so I am completely stucked... Can anyone help me with this? Using pywinauto module is not necessary if there is an easy way!!
Thanks in advance!!

Anyone know a good way to automate clicking in an HTML <canvas> element in Python? (E.g., in a pixel canvas)

Last year reddit released a social experiment for April Fool's, a pixel canvas that allowed users to click a color into any pixel on the grid; and they would have to wait a certain amount of time before they could click again. After the experiment ended, several duplicate sites sprang up, among them http://origami64.net/place.php.
I wanted to make a bot that would go and automatically click on a given pixel in the canvas, and since I was getting enrolled in a Python class at that point in time, I figured I would learn Python in order to do it. Initially I tried to use one of the bots for the original canvas as a template (https://github.com/hithroc/fixRD/blob/master/img.py), but the new canvas was too different for that to work.
When I discovered the selenium module though, I thought it would be a good idea to try it out, so I compiled this code:
import time
import random
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://origami64.net/place.php")
black=driver.find_element_by_id('#222')
black.click()
canvas=driver.find_element_by_id('c0')
time.sleep(5)
x=0
y=0
while (1):
driver.execute_script("window.scrollTo(x, y)")
canvas.click()
x=x+1
y=y+1
time.sleep(2.5)
I know, pretty insignificant. And it doesn't doesn't do much except click on one spot on the canvas.
So how do I get it to click on other pixels? I tried implementing move_to_element_with_offset, but that continuously resulted in MoveTargetOutOfBoundsException errors, because the canvas is larger than the viewport in the window. So you have to zoom out to see the whole canvas in order for it to be possible to place a pixel.
I spent a few weeks trying to get move_to_element_with_offset to work for me, and even after I did, I was unable to accomplish my goal, because it turns out that the offset coordinates in selenium are not counted by pixels of the elements, but by literal pixels on the screen. So unless there is a way to get the zoom perfectly linear with the pixels on the screen in ratio to those in the < canvas> element, I can't really choose the extent of my offset.
So selenium seems to be a dead end for me. I realize that when the canvas receives a click, though, there is a JavaScript code that initiates at http://origami64.net/jscripts/place.js. If I can get the portion of the script that determines where the mouse location is when the "click" occurred to run at my command, and I can feed the mouse x, y coordinates with my own values, maybe then I could make this work? I don't know.
Honestly I'm not sure which direction to go at this point.
Okay, through research I have determined that it is not possible to do this easily. It is much more convenient to just use web scraping if you want to bot.

How do I scroll a wxPython wx.html.HtmlWindow back down to where it was when the user clicked a link?

I am using a wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll down a list of links in a window smaller than the list. When they click on a link, I need to repaint the web page, but I want to return the page position back to where they clicked it.
I've tried MouseEvent.GetLogicalPosition() on the event, but it wants a DC and the best I've been able to do is get the same information as GetPosition(), so I must not be feeding it the right one.
I also tried HtmlWindow.CalcScrolledPosition(), but apparently that isn't available in HtmlWindow because I get a NotImplementedError...
What I would like is a scroll position that can be derived from the MouseEvent, or the OnLinkClicked information.
I know about HtmlWindow.ScrollToAnchor(), but it's flaky and unaesthetic -- I would prefer to bypass it if possible so that I can scroll back exactly to where the user clicked.
Thanks!
how about having a look at the source of wxHtmlWindow for inspiration? for example at wxHtmlWindow::LoadPage(): it
// store[s the current] scroll position into history item:
int x, y;
GetViewStart(&x, &y);
(*m_History)[m_HistoryPos].SetPos(y);
this saved scroll position is used in wxHtmlWindow::HistoryBack():
Scroll(0, (*m_History)[m_HistoryPos].GetPos());
Refresh();
to go back to the saved position.
i would assume that this built-in "go-to-the-last-position-in-window" handling isn't the most "flaky and unaesthetic". could something similar work for you, too?
Maybe a bit late, but with some tips from ax, and some hints from here, I think that calling:
scrollpos = wx.html.HtmlWindow.GetViewStart()[1]
and storing that, and then later doing a call to:
wx.html.HtmlWindow.Scroll(0, scrollpos)
works for me. Of course, you do need to change wx.html.HtmlWindow to an actual reference to an instance.
Here is what I am doing to scroll page to previous position.
I do this to avoid blinking.
pos = self.GetViewStart()[1]
self.Freeze()
self.SetPage(src)
if save_scroll_pos:
self.Scroll(0, pos)
self.Thaw()
Usually, click events are trigged by MouseUp events. If you track the mouse position by capturing any MouseDown events, you will know where the last click (MouseUp) happened, and that should allow you to reconstruct things.
For this particular problem, you might have to do a bit more work in MouseDown like checking if they are within the wxHtmlWindow control and if so, then saving something like a line number.

Categories