Skip to content Skip to sidebar Skip to footer

Python Selenium Disable Os Pop-ups

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 p

Solution 1:

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()

Solution 2:

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()

Post a Comment for "Python Selenium Disable Os Pop-ups"