How to click button in 'alert' message on the webpage with PyQt4 - python

On the webpage, when I create a new user, alert message displayed that 'New user was created'. And in order to continue, I have to click button 'ok'. So the thing is I don't really know how to click it.
when I need to click a regular button I do something like this:
doc = self.page().currentFrame().documentElement()
submit_button = doc.findFirst('input[id=my-submit-button]')
submit_button.evaluateJavaScript('this.click()')
But how to click button in alert message?

You are looking for the QWebPage::javaScriptAlert ( QWebFrame * frame, const QString & msg ) function:
This function is called whenever a JavaScript program running inside
frame calls the alert() function with the message msg.
The default implementation shows the message, msg, with
QMessageBox::information.

Related

Close Discord message on button click

I have a select menu with a submit button. When submit is clicked I want to close the current message, submit the data and then open a new select menu but I am having trouble figuring out how to have the message close.
How can I have the current menu and button close when the submit button is clicked?
Thanks in advance for your help.
To turn my comment into an answer; you can just delete the message on button press. For example, my Cancel buttons look a little like this:
#discord.ui.button(label="Cancel", style=discord.ButtonStyle.red, row=3, disabled=False, emoji="✖️")
async def cancel_callback(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.message.delete()
This is within a custom View class so might have to be adapted for your needs - but using the interaction.message attribute to delete the message is the way to go.

Button click is not fetching the correct v_model value of combobox

I am trying to get the value of a combobox on a button click and process the value in the button click handler. However, the combobox.v_model seems to be updated correctly only after the button click handler has exited.
Here is what I did (code below):
enter string 'xxx' in the combobox when widgets show up
click on the button thereafter and fetch the value of combobox.v_model
Expected to retrieve 'xxx', but retrieved '' (empty string) instead
Is there a way to retrieve the combobox content with a button click immediately after input?
Note: when 'Enter' / 'TAB' is pressed before the button click, all works, but not if the button is pressed immediately after input in the combobox.
import ipyvuetify as vue
name = ''
# vuetify combobox and button
combobox = vue.Combobox(label="Enter name", v_model="", items=[], autofocus=True)
btn = vue.Btn(children=['Process name'])
component = vue.Row(children=[
vue.Col(children=[combobox]),
vue.Col(children=[btn])
])
# --- event handler -------------------------
# Some processing of the combobox input needs to happen
# on a button click, but v_model is not updated
def on_button_clicked(widget, event, data):
print(f"btn clicked: {combobox.v_model=}")
name = combobox.v_model
print(f'btn clicked: {name=}')
# do some processing with name here
btn.on_event("click", on_button_clicked)
display(component)
Could be a bug in Vuetify: vuetifyjs/vuetify#12567 (also refer to this post on the ipyvuetify issue tracker).

Handling Context Menu of the taskbar icon with pywinauto

I am trying to automate the exiting operation on one of the apps. The app's icon is located in the taskbar. I was successfull in opening that icon's context menu with the modified code that I have found on stackoverflow:
import pywinauto
from pywinauto.application import Application
import time
app= "Service is enabled."
app = Application(backend="uia").connect(path="explorer.exe")
st = app.window(class_name="Shell_TrayWnd")
t = st.child_window(title="Notification Chevron").wrapper_object()
t.click()
time.sleep(1)
list_box = Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
list_box_win = list_box.window(class_name="NotifyIconOverflowWindow")
list_box_win.wait('visible', timeout=30, retry_interval=3)
# time.sleep(1)
appOpened= list_box_win.child_window(title = app)
appOpened.click_input(button = "right")
After the execution of the code above I get to the point when the context menu is opened:
The next thing that I want to do is to click on Exit, I have tried doing it by specifying the mouse click coordinates, but I have noticed that the position of the parent icon is changing from time to time.
What I would like to do is to get the handle on the Exit button and send click automatically.
------Edit-------
The icon is located in the hidden icons
So you want to access to the right click context menu. As said in this answer, you can do something like :
listbox.PopupMenu["Exit"].set_focus().click_input()

Remove Keyboard after clicking URL from InlineKeyboardButton

I'm creating a wrapper for /commands in python
I created an InlineKeyboardButton with a URL to chat the bot in private. I want the button to remove or disappear, just not show after the user clicks the url button.
I have used the generic wrapper from the telegram tutorials.
However, I am a "newb" :) Always trying to learn something new I can share.
In this case, I've become stuck.
Unlike callback_data where data can be sent to another button to edit the message. The URL doesn't send anything. I just want the button to vanish or the best alternative hide or something.
Any Ideas??
what direction to move in :)
I have looked into ReplyKeyboardRemove and OneTimeKeyboard but either my syntax is off or It isn't possible with a URL button
def myrestricted(func):
#wraps(func)
def wrapped(bot, update):
user = update.message.from_user.username
if update.message.chat.type != "private" :
group = update.message.chat.id
if user not in ADMIN_ONLY:
button = [InlineKeyboardButton("7heUnknown_Bot", url='t.me/7heUnknown_Bot',],
bot.send_message(chat_id=update.message.chat_id, text="Please click the button below to talk with me privately")
return
return func(bot, update)
return wrapped```
When the user clicks on the URL button I want the button to disappear.
Unfortunately, you can't.
InlineKeyboardButton with a URL only displays the button for users to open a link. As far as I know, there's no event in Telegram's API that can be fired when the user actually opens the link (or even clicks on the button!)

Python tkinter raise exceptions and wait for button press

I'm new in Tkinter and I'm currently trying to create a small game. When something happens in the game I want to create a pop-up window which will inform the user about any changes. This is the code that I have written for it.
def message(self, text):
top = tkinter.Toplevel(width=50, height=25)
top.title("Message")
msg = tkinter.Message(top, text=text)
msg.pack()
ok = tkinter.Button(top, text="OK", command=top.destroy)
ok.pack()
My two questions are:
Can I replace this by an exception that will create an "Error Message" window? If it isn't necessary then can I use it to be raised by the exception?
I want the user to be forced to see and read the message, so how can I freeze the main window(the user can't click on anything else) until he presses the OK button on the pop-up window?
Use:
top.grab_set()
To show Error Message you can use tkmessagebox.showerror().

Categories

Resources