0

I am trying to automate the file downloading process with selenium in Python. Until now I succeeded in writing the code to realize it. But there is just a little problem which is pretty disturbing: Each time I launch the program in Firefox (I use webdriver.Firefox()), there is always an OS pop-up which asks me allow the website to use 'Microsoft Office' and blocks the whole program. Since it is an OS problem, I cannot interact with it using selenium...I also tried driver.switch_to_alert() method but it didn't work.

Do you know how to fix it?

Thank you very much!!

Andersson
  • 51,635
  • 17
  • 77
  • 129
SXC88
  • 227
  • 1
  • 5
  • 16
  • show exact code you used to confirm alert. Also check this ticket http://stackoverflow.com/questions/26843852/how-to-get-rid-of-allow-website-to-run-silverlight-alert-on-firefox-using Seem to be same issue. It's on `Java`, but solutions should be quite similar – Andersson Nov 10 '16 at 15:49
  • Once you `switch_to_alert()` are you accepting/rejecting alert? –  Nov 10 '16 at 15:50
  • You can detect the pop up by XPATH or CSS selector, if it exists click the button. I resolve my POPUPs problem with that. – Wonka Nov 10 '16 at 16:00
  • Here I post the alert code below. But it doesn't work since the pop-up box I got was from the OS. – SXC88 Nov 10 '16 at 18:47
  • @Wonka nope, it is from the system, so I cannot track it by Xpath or CSS – SXC88 Nov 10 '16 at 19:07
  • @Andersson Yes, I checked the post, but I am not sure if I got the idea. I created a new 'ProfileToolsQA' , but how can I add it to the existing 'set.preference' configuration as I posted below. In addition, I manually disabled the "Microsoft Office" choice in plugins in Firefox, but it still asks every time I launch the program. – SXC88 Nov 11 '16 at 10:08
  • @SXC88, If you've already created a new Profile, then use `fp=webdriver.FirefoxProfile(your_path_to_profile)` instead of `fp=webdriver.FirefoxProfile()` – Andersson Nov 11 '16 at 10:18
  • @Andersson Cool! It works now, thank you very much! – SXC88 Nov 11 '16 at 11:06
  • @Andersson Hi maybe you also want to have a look at this post? Thank you!! http://stackoverflow.com/questions/40616351/python-selenium-click-doesnt-work – SXC88 Nov 15 '16 at 20:30

2 Answers2

0
try:
        WebDriverWait(driver, 40).until(EC.alert_is_present(),
                                      'Timed out waiting for PA creation ' +
                                      'confirmation popup to appear.')

        alert = driver.switch_to.alert()
        alert.accept()
SXC88
  • 227
  • 1
  • 5
  • 16
-1

Here is my entire code, the pop-up appears between those two lines (after login):

loginButtonElement.click()
BBElement=WebDriverWait(driver,50).until(lambda driver:driver.find_element_by_xpath(BBButton))

the code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import unittest
import os




class LoginTest(unittest.TestCase):
  def setUp(self):

    fp=webdriver.FirefoxProfile()

    fp.set_preference("browser.download.folderList",2)
    fp.set_preference("browser.download.manager.showWhenStarting",False)
    fp.set_preference("browser.download.dir", "D://doc")
    fp.set_preference("pdfjs.disabled", True)
    fp.set_preference("plugin.disable_full_page_plugin_for_types", "application/pdf")
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")


    self.driver=webdriver.Firefox(firefox_profile=fp)
    self.driver.get("myurl")

  def test_Login(self):
    driver=self.driver

    emailFieldID="userNameInput"

    passFieldID="passwordInput"
    loginButtonID="submitButton"
    BBButton="(//a[contains(@href,'blackboard')])"
    coursebutton="(//a[contains(@href,'Course&id=_4572_1&url')])[1]"

    docbutton="(//a[contains(@href,'content_id=_29867_1')])"
    conbutton="(//a[contains(@href,'content_id=_29873_1')])"
    paperbutton="(//a[contains(@href,'/xid-26243_1')])"

    emailFieldElement=WebDriverWait(driver,20).until(lambda driver:driver.find_element_by_id(emailFieldID))

    passFieldElement=WebDriverWait(driver,20).until(lambda driver:driver.find_element_by_id(passFieldID))
    loginButtonElement=WebDriverWait(driver,20).until(lambda driver:driver.find_element_by_id(loginButtonID))

    emailFieldElement.clear()
    emailFieldElement.send_keys("username")
    passFieldElement.clear()    
    passFieldElement.send_keys("password")
    loginButtonElement.click()
    BBElement=WebDriverWait(driver,50).until(lambda driver:driver.find_element_by_xpath(BBButton))
    BBElement.click()
SXC88
  • 227
  • 1
  • 5
  • 16