PyAutoGui - locate doesn't see the right-click menu - python-3.x

I have the code below that basically identify the small chrome icon in the windows toolbar, right-click on it using pyautogui and then it should locate the "New Window" option. The problem I face is that, even if I take a screenshot after the right-click, the small menu doesn't show up, making it impossible to locate the "New Window" option.
# this part works
chrome_small_icon = r"C:\Users\chrome_small_icon.png"
elem = pyautogui.locateOnScreen(chrome_small_icon)
elem_center = pyautogui.center(elem)
pyautogui.click(elem_center, duration=0.5, button="right")
time.sleep(0.5)
im_after_right_click = pyautogui.screenshot()
# this part finds zero element, reason being, the right-click menu is like a ghost...
chrome_new_window = r"C:\Users\new_window_text.png"
elements = pyautogui.locateAllOnScreen(chrome_new_window)
does anybody have any suggestion about how to locate elements inside the menu that appears when we right click on an element?
Thanks
EDIT
it seems this issue happens only if I right click on the windows toolbar. It does work if I right click on other locations of the screen.

Instead of trying to locate the new window text use the keyboard to select the new window option. I just ran the following code on MacOS and I was successfully able to open a new Chrome window:
import pyautogui
import time
pyautogui.rightClick(pyautogui.center(pyautogui.locateOnScreen('chrome.png')))
#chrome.png is an image of the chrome icon
pyautogui.typewrite('new window')
pyautogui.press('enter')

Related

How to scroll android screen by AndroidViewClient

Currently, I'm working on Snapchat and I want to scroll the screen slightly
1.device.vc.dump()
2.device.vc.findViewByIdOrRaise("com.snapchat.android:id/neon_header_avatar_container").touch()
3.device.vc.dump()
Now I want to scroll the screen to findViewWithText My friends. so how I can do it,
You can use culebra and generate the python code needed for scrolling or dragging.
Run
culebra -Gu --scale=0.25
then right-click and open the command dialog, select Drag dialog and grab the points clicking on the device image (using Settings here as an example)
something like the following code will be generated
device.dragDip((184.73, 699.64), (176.0, 443.64), 1000, 20, 0)
vc.sleep(1)
vc.dump(window=-1)
When executed you will see the device scrolling.

PYQT5 Simulating Window Menu MacOS

I'm attempting to simulate the native MacOS "Window" menu in PYQT5. I am able to cycle through open windows via my menu and indicate the active window by setting its checked state to True.
I would like to also simulate the MacOS HID icon assigned when a window is minimized like this:
However, the closest I have been able to come is with a QIcon, which isn't quite right (the icon isn't quite right either, but I can live with that).
bring = self.view_menu.addAction('&Bring to Front', self.foo)
bring.setIcon(QtGui.QIcon("diamond.png"))
Is it possible to have the QIcon displayed in the left menu column (aligned with the checkmark) or otherwise display a diamond for an action item like MacOS? I didn't see any parms for the QIcon class that appeared to do this.

Hide bottom border from QtDesigner designed UI

I have created a very simple UI with the QtDesigner (using pyqt5) and everything is ok except that there is a non-usable whitespace-border on the bottom of it. <
Does anyone have any idea how to remove this border - or write a simple sentence on it (something like Alt + F11 -> toggle)?
Is the above possible from within the QtDesigner environment?
Since you are using the QMainWindow as a window then that blank space is the QStatusBar, if you want to remove it then right click on the window and select "Remove Status Bar":
If you want to add then you must right click and select "Create Status Bar".

selecting item from context-menu after right click

I have a website that i want to crawl but as it is in chinese i have to firsttraslate it to english and then crawl for which i want the script to right click and open the context menu and then select translate to english. my script is able to right click and open the context menu but not able to select the translate to english option
i have used selenium webdriver for chrome along with python3.7 and have written the code accordingly for right clicking and opening the context menu but stuck on selecting the option translate to english
path_to_chromedriver = 'C:/Users/Administrator/AppData/Local/Programs/Python/Python37-32/chromedriver_new.exe'
driver =webdriver.Chrome(path_to_chromedriver)
driver.get("https://tmall.com")
your_link = driver.find_element_by_xpath('//*[#id="header"]/div/div/div/div[1]')
actionChains = ActionChains(driver)
actionChains.context_click(your_link).perform()
i expect the output to click the option translate to english from context menu
Try simulating pressing the UP key several times (in my context menu it is 4th from the bottom in order to reach "Translate to English"):
actionChains.context_click(your_link).key_down(Keys.UP).key_up(Keys.UP).key_down(Keys.UP).key_up(Keys.UP).key_down(Keys.UP).key_up(Keys.UP).key_down(Keys.UP).key_up(Keys.UP).key_down(Keys.RETURN).key_up(Keys.RETURN).perform()

Coded UI Test Builder not recognizing buttons on the pop-up window

When I click the crosshairs icon on the Coded UI Test Builder and drag it over to the pop-up window buttons (Run and Cancel), it is unable to locate and find the Properties of them on the pop-up window.
Does any one know how I can know the properties of the Run button on the pop-up window?
That window appears to be a Java window, which is not supported by Coded UI.
You may be able to extend your tests to interact with the Window:
https://blogs.msdn.microsoft.com/gautamg/2010/01/05/1-introduction-to-coded-ui-test-extensibility/
Alternatively, if you can detect if the window is present, you may be able to emulate the keypresses required to dismiss/approve the window (e.g Enter, or Tab + Enter). Or, if the window's location is predictable, emulate a click at the desired location.

Resources