How to click on open application alert using Selenium
Asked Answered
U

7

6

I am trying to click on open application alert using Selenium, and I am getting this error

NoAlertPresentException: Message: no such alert

So basically I am trying to open zoom application from the browser

enter image description here

And here is my code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

driver = webdriver.Chrome(executable_path='chromedriver/chromedriver')
driver.get("https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09")

try:
    WebDriverWait(driver, 5).until(EC.alert_is_present(), 'Timed out waiting for alerts to appear')
    alert = driver.switch_to.alert
    alert.accept()
    print("alert accepted")
except TimeoutException:
    print("no alert")
Ungovernable answered 2/6, 2020 at 14:19 Comment(0)
O
1

Because this is not a browser Alert, rather OS App selector, you cannot interact with it within Selenium.

See: Selenium C# How to handle Alert "Open Pick an app"?

You can prevent these App selectors by default by using the --disable-default-apps flag when starting up Chrome.

Overflight answered 5/6, 2020 at 16:56 Comment(0)
U
2

Thanks to NetworkMeister, I end up using default app method, Like the following:

1- Open Firefox and go to zoom URL, when Launch application appear choose zoom and click on remember my choice and click open link

2- Go to firefox and paste this about:support then search for Profile Folder and copy the path

3- Go to your code and add profile parameter to selenium driver and use the path you have copied

fp = webdriver.FirefoxProfile('C:/Users/ASUS//AppData/Roaming/Mozilla/Firefox/Profiles/0rgewd47.default-release')
driver = webdriver.Firefox(executable_path='geckodriver', firefox_profile=fp)
driver.get('https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09')

Now zoom application will open automatically when you execute this code


Note: Firefox profile contains all of your browsing data, If you want to share your code I suggest creating a new Firefox profile, For more information look here

Ungovernable answered 5/6, 2020 at 23:40 Comment(1)
Works! Many Thanks!Jenna
T
2

From what I noticed is that when you open any such link in the browser the URL changes a bit. With this you can figure out the link for opening it in the browser. For example I have this zoom meeting

https://us04web.zoom.us/ w/ 76919011107?tk=5Q_zikLZhvWlqc_nzVcYaHoTyo7JuDY6cvLB9y9t0zc.DQIAAAARDLr3IxZHM21mSHFzYlR6Q0xZdnNhcnUwbUV3AAAAAAAAAAAAAAAAAAAAAAAAAAAA&pwd=QANkcTdsNlpjYWY4czZvd3FHV0NLQT09

Now this would open a popup like you showed in the browser. (This link is not real. I changed 2-3 characters in the URL for security reasons). But now if you try this link

https://us04web.zoom.us/ wc/join/ 76919011107?tk=5Q_zikLZhvWlqc_nzVcYaHoTyo7JuDY6cvLB9y9t0zc.DQIAAAARDLr3IxZHM21mSHFzYlR6Q0xZdnNhcnUwbUV3AAAAAAAAAAAAAAAAAAAAAAAAAAAA&pwd=QANkcTdsNlpjYWY4czZvd3FHV0NLQT09

This will directly open the meeting in the browser. Note the change in URL has been shown in bold (I had to add spaces because of that on both sides). Now this may change over time but fundamentally by comparing the 2 links you should find a way to achieve this.

Similarly for Microsoft Teams if you add "_#" after the domain you can join the meeting through the browser

For example if I want to open this link in the browser

https://teams.microsoft.com/l/meetup-join/19%3ameeting_NTRlM2JiZWUtZjNiMC00ZjVhLTlmMWEtZDcxYjBmYjdhY2Nl%40thread.v2/0?context=%7b%22Tid%22%3a%22e85f2c00-2730-4ca5-b8d8-609b15bd4746%22%2c%22Oid%22%3a%223bf1c992-96b1-4a87-808f-dcc5bb2009c9%22%7d

I'll have to write

https://teams.microsoft.com/_#/l/meetup-join/19%3ameeting_NTRlM2JiZWUtZjNiMC00ZjVhLTlmMWEtZDcxYjBmYjdhY2Nl%40thread.v2/0?context=%7b%22Tid%22%3a%22e85f2c00-2730-4ca5-b8d8-609b15bd4746%22%2c%22Oid%22%3a%223bf1c992-96b1-4a87-808f-dcc5bb2009c9%22%7d

These patterns can be found by observing the link before and after opening it in the browser.

Terbia answered 8/5, 2021 at 3:29 Comment(1)
Good alternative solutionUngovernable
O
1

Because this is not a browser Alert, rather OS App selector, you cannot interact with it within Selenium.

See: Selenium C# How to handle Alert "Open Pick an app"?

You can prevent these App selectors by default by using the --disable-default-apps flag when starting up Chrome.

Overflight answered 5/6, 2020 at 16:56 Comment(0)
C
1

I encountered this problem my self. Apparently this is related to the alert being OS level rather than being at a browser level.
The simplest solution I found is https://pypi.org/project/PyAutoGUI/ which allows you to pass an img of the button you want to click and then it locates it on the screen. You can call python directly from java.
Native java solution: https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html this allows you to automate stuff like "move mouse to position" -> "mouse click" etc.

EDIT: the main downside is that the webdriver cannot be run in headless mode as PyAutoGUI makes a screenshot of the screen to locate the button.

Cecilacecile answered 2/3, 2021 at 10:29 Comment(0)
W
0

This is not the best way but I resolved the issue by sending keyboard commands. It works on Windows, I haven't tested on different os.

import pyautogui

sleep(3)                           # sleep until pop up shown
pyautogui.press('tab', presses=2)  # navigate to open button
pyautogui.press('enter')           # open application
Wesleyanism answered 26/10, 2022 at 14:43 Comment(0)
K
0

For me using Robot class worked for teams.

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
Kozhikode answered 8/2, 2023 at 19:46 Comment(0)
A
0

For Edge Driver, here is the way to handle it by using the profile:

Find your profile path:

In Edge, go to edge://version -> Profile path It should be something like this: C:\Users[username]\AppData\Local\Microsoft\Edge\User Data\default[profile name]

Create selenium options to use the profile

myoptions = webdriver.EdgeOptions()
myoptions.add_argument(r"user-data-dir=C:\Users\[username]\AppData\Local\Microsoft\Edge\User Data\Default")
myoptions.add_argument("profile-directory=[profile name]")
driver = webdriver.Edge(executable_path=r"[path_to_edge_driver]\msedgedriver.exe",options=myoptions)
driver.get('https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09')
Amphibolite answered 27/2, 2023 at 1:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.