Automated Qualtrics Login

Overview

The **Automated Qualtrics Login** module is designed to securely and reliably automate the login process to the Qualtrics survey platform using institutional credentials. This includes handling multi-step authentication procedures such as two-factor authentication (2FA) and browser trust prompts. The automation mimics human-like interactions to minimize detection and ensure smooth login flow. This module is critical because Qualtrics restricts API access to authenticated users, so establishing a valid session programmatically is a prerequisite for all subsequent collaboration management actions.

Core Concepts and Purpose

This module solves the problem of programmatically authenticating to a web platform that uses complex web-based authentication flows, including multi-factor authentication and browser trust confirmations, which cannot be handled by simple HTTP requests alone.

How the Module Works

1. Selenium Browser Automation

The module uses Selenium WebDriver to programmatically control a Chrome browser instance:

2. Human Interaction Simulation

To avoid bot detection and ensure smoother automation, the module simulates human behavior through:

def _human_type(element: WebElement, string: str) -> None:
    for char in string:
        if char in ["!", ".", "?", ","]:
            time.sleep(random.uniform(.6, 1))
        elif char == " ":
            time.sleep(random.uniform(.14, .20))
        else:
            time.sleep(random.uniform(.1, .13))
        element.send_keys(char)

3. Handling Two-Factor Authentication and Trust Prompts

After submitting credentials, the login flow may require:

This is achieved by polling the browser state in a loop, using helper methods:

while not self._at_qualtrics(driver):
    if self._check_for_trust_browser_page(driver):
        trust_browser_button = driver.find_element(By.ID, 'trust-browser-button')
        trust_browser_button.click()
        self.human_sleep()

4. Session Cookie Extraction and Transfer

Once authenticated and navigated to the main Qualtrics projects page, the module extracts all session cookies from the Selenium-controlled browser and inserts them into a persistent `requests.Session` object. This session is then used for all subsequent API calls to manage survey collaborations.

cookies = driver.get_cookies()
for cookie in cookies:
    self.session.cookies.set(cookie["name"], cookie["value"])

This cookie synchronization enables authenticated HTTP requests without requiring further browser automation.


Interactions with Other Modules


Important Concepts and Design Patterns


Key Code Snippets

Login Sequence Initiation

def login(self) -> None:
    nyu_username: str = input('NYU username:').strip()
    nyu_password: str = getpass('NYU password:').strip()
    self._selenium_login(nyu_username, nyu_password)

Selenium Automated Login Flow

def _selenium_login(self, nyu_username: str, nyu_password: str) -> None:
    options = Options()
    options.add_argument("--headless")
    options.add_argument(f"user-agent={self.user_agent}")
    driver = webdriver.Chrome(options=options)
    driver.get(f"https://{self.subdomain}.qualtrics.com/ControlPanel/")

    username_input = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'username')))
    self._human_type(username_input, nyu_username)

    password_input = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'password')))
    self._human_type(password_input, nyu_password)

    login_button = WebDriverWait(driver, 20).until(EC.presence_of_element_located(
        (By.XPATH, '//button[contains(text(), "Login") and @type = "submit"]')))
    login_button.click()

    while not self._at_qualtrics(driver):
        if self._check_for_trust_browser_page(driver):
            trust_browser_button = driver.find_element(By.ID, 'trust-browser-button')
            trust_browser_button.click()
            self.human_sleep()

    driver.get(f'https://{self.subdomain}.qualtrics.com/Q/MyProjectsSection')

    cookies = driver.get_cookies()
    for cookie in cookies:
        self.session.cookies.set(cookie["name"], cookie["value"])

    driver.quit()

Mermaid Sequence Diagram: Automated Qualtrics Login Flow

sequenceDiagram
    participant User
    participant CollaborationClient
    participant SeleniumBrowser
    participant QualtricsLoginPage
    participant TwoFactorAuth
    participant QualtricsMainPage

    User->>CollaborationClient: Provide username & password
    CollaborationClient->>SeleniumBrowser: Launch headless Chrome
    SeleniumBrowser->>QualtricsLoginPage: Open login page
    CollaborationClient->>SeleniumBrowser: Type username (simulate human)
    CollaborationClient->>SeleniumBrowser: Type password (simulate human)
    CollaborationClient->>SeleniumBrowser: Click login button
    SeleniumBrowser->>TwoFactorAuth: Wait for 2FA completion
    alt Trust Browser Prompt Appears
        SeleniumBrowser->>TwoFactorAuth: Click "Trust Browser" button
    end
    SeleniumBrowser->>QualtricsMainPage: Load main projects page
    SeleniumBrowser->>CollaborationClient: Extract session cookies
    CollaborationClient->>User: Login complete, session ready

This diagram illustrates the step-by-step interaction from receiving user credentials to establishing an authenticated session ready for API use.


This documentation explains the **Automated Qualtrics Login** module's purpose, workflow, key functionalities, and integration points, supported by code references and a visual login sequence diagram.