예제 #1
0
def login(email, password):
    """
    Performs a Login to the Facebook platform.
    :param email: The used email account.
    :param password: Its password
    :return: Returns the logged Selenium web driver and the user name string.
    """
    logger.info('Init Firefox Browser')
    profile = webdriver.FirefoxProfile()
    profile.set_preference('dom.disable_beforeunload', True)
    driver = webdriver.Firefox(profile)

    driver.get('https://www.facebook.com')

    logger.info('Log in - Searching for the email input')
    get_by_xpath(driver, '//input[@id="email"]').send_keys(email)

    logger.info('Log in - Searching for the password input')
    get_by_xpath(driver, '//input[@id="pass"]').send_keys(password)

    logger.info('Log in - Searching for the submit button')
    get_by_xpath(driver, '//input[@type="submit"]').click()

    logger.info('Log in - get the user name')
    user_name = get_by_xpath(driver, '//a[@class="fbxWelcomeBoxName"]').text

    logger.info('Log in - Saving the username, which is: %s' % user_name)
    return driver, user_name
def _get_firefox(bin_path=None, profile_name=None):
    import selenium.webdriver.firefox.webdriver as fwb
    profile_path = os.path.join(
        os.path.split(__file__)[0], profile_name or "selenium-firefox-profile")
    if not os.path.exists(profile_path):
        os.makedirs(profile_path)
    ff_profile = fwb.FirefoxProfile(profile_path)
    ff_path = bin_path or FIREFOX_CONF["osx"]
    ff_bin = fwb.FirefoxBinary(firefox_path=ff_path)
    driver = fwb.WebDriver(firefox_profile=ff_profile, firefox_binary=ff_bin)
    return driver
예제 #3
0
    def downloadfile(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", os.getcwd())
        fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
                          "application/octet-stream,application/xlsx")

        browser = webdriver.Firefox(firefox_profile=fp)
        browser.get("http://ehrtest.source3g.com/humres/#/emp_import")
        browser.find_element_by_xpath(
            ".//*[@id='app']/div/div[3]/div/div[2]/div[2]/a")
예제 #4
0
def start_browser():
    opts = Options()
    # if headless == "y":
    opts.add_argument("--headless")
    firefox_profile = webdriver.FirefoxProfile()
    firefox_profile.set_preference('permissions.default.image', 2)
    firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                   False)
    try:
        driver = Firefox(firefox_profile=firefox_profile, options=opts)
    except WebDriverException:
        print("Geckodriver not detected, it will now be downloaded...")
        gdd = GeckoDriverManager()
        gdd.download_and_install()
        driver = Firefox(firefox_profile=firefox_profile, options=opts)
    return driver
예제 #5
0
    def setUp(self):
        db.create_all()

        if not os.path.exists(self.download_dir):
            os.makedirs(self.download_dir)

        profile = webdriver.FirefoxProfile()
        profile.set_preference("browser.download.folderList", 2)
        profile.set_preference("browser.download.manager.showWhenStarting", False)
        profile.set_preference("browser.download.dir", self.download_dir)
        profile.set_preference(
            "browser.helperApps.neverAsk.saveToDisk",
            "text/plain,text/csv,text/html,application/zip"
        )
        self.browser = webdriver.WebDriver(firefox_profile=profile)
        self.browser.implicitly_wait(3)
        self.browser.set_window_size(1280, 1024)