1

I am trying to make a web automation program that opens my school's app. Our school is using Adobe Connect. When I try to open the installed app, it gives me a confirmation alert. Which is not inspectable and can't define any XPath or... So, how can I handle this? I have read many Q\As but I can't manage it. Here is my code:

from selenium import webdriver
import time

url = "http://78.157.45.27/eleven203/?OWASP_CSRFTOKEN=edd648edd5" \
      "e9bf51c3196210963bd5470d6c7af82e0ec636789dfafe5fc558dc&proto=true"
browser = webdriver.Chrome()
page = browser.get(url)
time.sleep(1)

my_user_name = "***"
my_password = "***"
time.sleep(1)

user_name = browser.find_element_by_id(id_="name")
password = browser.find_element_by_id(id_="pwd")
submit_button = browser.find_element_by_id(id_="login-button")
time.sleep(1)

user_name.click()
user_name.clear()
user_name.send_keys(my_user_name)

password.click()
password.clear()
password.send_keys(my_password)

submit_button.click()
time.sleep(5)

And here is the solution I tested from other questions but not worked(attach it at the end of the code above):

ale = browser.switch_to.alert()
ale.accept()

The error message:

selenium.common.exceptions.NoAlertPresentException: Message: no such alert

I also added the confirmation alert, for your ease.

enter image description here

Mani
  • 45
  • 12
  • Can you please post the error message you get. Also take a look at the HTML and see if the "Open Adobe Connect" element is within an `iframe`. – Peaceful James Oct 07 '20 at 11:09
  • @PeacefulJames Yes, the error message is there. Also, I told it is not inspectable. – Mani Oct 07 '20 at 11:11
  • 1
    Interesting... I suggest for you to search about executing any javascript code that could close that or press okay. It is possible to do that in selenium.. for example `driver.execute_script("document.getElementsByClassName('sample-class')[0].click()")` Check it out here [link](https://stackoverflow.com/questions/7794087/running-javascript-in-selenium-using-python) – Ice Bear Oct 07 '20 at 11:25
  • @IceBear Actually I don't want to bother myself with JS :) But I will check that out. Anyways, is there a full python way? – Mani Oct 07 '20 at 11:38
  • 1
    @ManiFaridi , probably this is what you're looking for [link](https://stackoverflow.com/questions/17676036/python-webdriver-to-handle-pop-up-browser-windows-which-is-not-an-alert) – Ice Bear Oct 07 '20 at 11:38
  • @IceBear I will work on these two ways until night, hope they work. Thanks. – Mani Oct 07 '20 at 11:44
  • I think the `ale.accept()` approach is not working because the alert takes some time to appear. See the last section in this guide: http://allselenium.info/python-selenium-handle-alerts-prompts-confirmation-popups/ where it explains "When we try to switch to alerts before it is displayed, we get NoAlertPresentException". – Peaceful James Oct 07 '20 at 13:01
  • @PeacefulJames But as you can see, I made a five seconds wait. Actually, the alert appears in just two seconds. I don't think it is because of not being loaded. – Mani Oct 07 '20 at 14:38
  • @PeacefulJames BTW I also checked it out, did what it said, and it didn't work either. – Mani Oct 07 '20 at 14:57

2 Answers2

2

I'm not sure if you can set apps to automatically open in the browser prefs or not, but you could always take a cropped screeshot of the button "Open Adobe Connect" and then use pyautogui to locate it and click it:

import pyautogui
button = pyautogui.locateCenterOnScreen('croppedScreenshot.png')
pyautogui.moveTo(button)
pyautogui.click()

Pyautogui sendkeys could work too I'd imagine.

0

An alternative way and a more secure one is to use this package. After the alert popup, you can program your app to press [Tab] and after that [Enter] in order to accept the alert.

Mani
  • 45
  • 12