Pyautogui to check if button is enable or disable - pyautogui

I would like to check if the desktop application button is clickable or not clickable. Is there any way to check this by using pyautogui?
I have a button name Login, it will be clickable if we provide both username and password text field.

This will need the images of the enabled and disabled button:
The images the program wants must be the same resolution.
import pyautogui
import keyboard #pip install keyboard
while True: # I added this loop to make sure that the image will be found.
# Sometimes the image is on the screen but pyautogui cant find it at once so i will make it check it repeatedly for the image.
res_d = pyautogui.locateCenterOnScreen('disabled.png') # capture the image by taking screenshot and cropping it
if res_d == None:
print("Enabled")
res_e = pyautogui.locateCenterOnScreen('enabled.png') # capture the image by taking screenshot and cropping it
if res_e == None:
print("Disabled")
if keyboard.is_pressed('q'): # Change this to the logic you want to use for breaking the loop.
break

Related

pyautogui - copying selected text

After manually selecting text in a browser window, I'd like to be able to use a hotkey to a .py file to copy the selected text to the Windows clipboard.
Have tried
pyautogui.hotkey("ctrl", "c")
and
pyautogui.keyDown('ctrl')
pyautogui.press('c')
pyautogui.keyUp('ctrl')
But neither works. From trying to troubleshoot this in a .ipynb (Jupyter notebook) file, it seems the issue is Window focus. If I do:
time.sleep(2)
pyautogui.hotkey("ctrl", "c")
And manually alt-tab from the code editor to the browser window with selected text, it works fine. Trying to automate the alt-tab doesn't seem to work b/c the alt-tab window stays on screen instead of briefly flashing the way it does when manually executed.
pyautogui.hotkey("alt", "tab") # alt-tab
time.sleep(2)
pyautogui.hotkey("ctrl", "c") #copy
So how can I select text in a browser window and then run .py file via hotkey but have the Window focus switch back to browser window before pyautogui.hotkey("ctrl", "c") executes?

Selenium Click Does not work, but Manual Click works

my code currently is:
driver.get("http://w2.leisurelink.lcsd.gov.hk/index/index.jsp")
window1 = driver.window_handles[0]
facility_basic_version = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/div[2]/div/div[3]/div/div[3]/div[1]/table/tbody/tr/td/div")
facility_basic_version.click()
# deselect selected captcha
window2 = driver.window_handles[1]
driver.switch_to.window(window2)
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, '//div[#class="kbkey button red_selected sel"]'))).click()
#Solve Captcha here
#
#
#
# Click continue at specific time
while len(driver.find_elements_by_xpath('//div[#class="kbkey button red_selected sel"]')) < 4:
print('captcha not done')
pyautogui.moveTo(634, 586, 0.5, pyautogui.easeInQuad)
time.sleep(0.3)
pyautogui.mouseDown()
pyautogui.mouseUp()
print('captcha done')
time.sleep(100)
I have a section to solve captcha, but since I haven't implemented that part yet, for testing purposes I am still solving captcha manually.
The problem: after solving captcha, I want to click the continue button. However, if try to find the element, then click on button, I would be met with an error (site knows I am using automation). I tried just starting up chromedriver, doing all the steps the bot would do manually and click the continue button manually, and the site would allow me to continue to next page. Hence, I tried using pyautogui to simulate mouse movement but still site gives me error.
A captcha is by definition designed to prevent automation, so I'm not surprised this does not work.
You might still be able to find a workaround and this might help: https://www.browserstack.com/guide/how-to-handle-captcha-in-selenium

Location icon does not always disappear when app is minimized on Android

I use Codename One to code my app. I've defined my UserLocationListener and use it successfully with the LocationManager.
In the main class' stop method I set LocationManager.setLocationListener (null) and the location icon disappears when the app is minimized.
However I'm also using a MapContainer with setShowMyLocation (true) and when the app gets minimized from a form that does not show the MapContainer the Location icon remains in the Android (Nougat) bar. Same behaviour when I get back to the form with the map from a form without it and then minimize the app.
Please note that if I don't setShowMyLocation (true) the icon disappears from whichever form.
Furthermore in the stop method I setShowMyLocation (false) but it looks like the listener does not stop.
What can I do to ensure that the location goes off when my app is minimized?
Thanks in advance

Flash - AS3 - TextInput - Slow

I am using Adobe Flash CS6 to create a form that the user fills out. There are 3 text input fields an a submit button. For the text input I am using the TextInput component (fl.controls.TextInput). When the flash first loads the background, labels, and button display and about a second later the 3 text input fields show up. Also when typing into the text fields there is a delay where I can type in something like "92683" and it seems to wait till I am done typing before the characters appear all at once. Any ideas on what could be causing these problems?
I have 2 layers. 1 layer has the button, textinput and labels. The other layer is the background that rotates between 3 background images every 10 seconds.
Try to use compressed bitmap images as background (don't use vectors).
You can compress here: File -> Publish Settings -> JPEG Quality.
If you are creating this in air for mobile phones then,
be sure you set render mode to GPU (Application Settings -> General -> Render Mode : GPU)
Hope this helps!

Adobe AIR bring to front

I have an adobe AIR app. When I send some data with a local connection from a web page, I want the app in front of the browser and all the other windows.
I tried with both activate() and orderToFront() but I have no results.
The only script working is:
window.alwaysInFront=true;
window.alwaysInFront=false;
But this doesn't give the focus to the app. So when I click the button on the browser, I have the app on the top, but if I click on the browser the app stays on top until I click on it (giving it the focus) and than I click on the browser window again. It works fine If I click on the browser top bar.
I think that activate() would solve the problem giving the focus to the app, but doesn't work.
Here it is the code (I worked with the native window to resize, minimize and maximize the window too). The function I call from local connection is "primopiano"
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.MovieClip;
import flash.display.NativeWindow;
var window = stage.nativeWindow;
function trascina (event:MouseEvent) {
window.startMove();
}
...
function primoPiano (event) {
trace("porto in primo piano...");
//window.activate(); // doesn't work
//window.orderToFront(); // doesn't work
window.alwaysInFront=true;
window.alwaysInFront=false;
}
Did I forgot to import something or do I have to define a different window to do this?
Thanks!
Nadia
Have a look at the Documentation and API Reference
AIR provides several methods for directly changing the display order of windows. You can move a window to the front of the display order or to the back; you can move a window above another window or behind it. At the same time, the user can reorder windows by activating them.
You can keep a window in front of other windows by setting its alwaysInFront property to true. If more than one window has this setting, then the display order of these windows is sorted among each other, but they are always sorted above windows which have alwaysInFront set to false. Windows in the top-most group are also displayed above windows in other applications, even when the AIR application is not active. Because this behavior can be disruptive to a user, setting alwaysInFront to true should only be done when necessary and appropriate. Examples of justified uses include:
Temporary pop-up windows for controls such as tool tips, pop-up lists, custom menus, or combo boxes. Because these windows should close when they lose focus, the annoyance of blocking a user from viewing another window can be avoided.
Extremely urgent error messages and alerts. When an irrevocable change may occur if the user does not respond in a timely manner, it may be justified to push an alert window to the forefront. However, most errors and alerts can be handled in the normal window display order.
Short-lived toast-style windows.
Note: AIR does not enforce proper use of the alwaysInFront property. However, if your application disrupts a user’s workflow, it is likely to be consigned to that same user’s trash can.
I have tried:
window.alwaysInFront = true;
window.alwaysInFront = false;
window.activate();
You could also try with a reference to a display object on the window stage:
displayObject.stage.nativeWindow.alwaysInFront=true;
//(where displayObject is your instance name)
And works fine. I'm using Adobe AIR 4