问题
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
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")
回答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.
回答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
来源:https://stackoverflow.com/questions/62154160/how-to-click-on-open-application-alert-using-selenium