[Python] Does Stripe allow programatic access to fields?

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to write a test that signs up a user in a Django application and subscribes to a Stripe subscription. The script is able to sign the user up and navigate to the page where the imbedded stripe pricing table is, however, it can't seem to interact with any of the elements in this pricing table.

    Is it simply just a matter of referencing the correct iframe? Or is there something I'm not appreciating ?


    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium import webdriver
    import time

    # driver = webdriver.Chrome()
    # driver.get("http://localhost:8000/")
    # iframes = driver.find_elements_by_tag_name("iframe")
    # for iframe in iframes:
    # print(f"Name: {iframe.get_attribute('name')}, ID: {iframe.get_attribute('id')}, src: {iframe.get_attribute('src')}")

    # driver.quit()


    class TestSIGNUP():
    def setup_method(self, method):
    self.options = webdriver.ChromeOptions()
    self.driver = webdriver.Chrome(options=self.options)
    self.vars = {}

    def teardown_method(self, method):
    self.driver.quit()

    def test_sIGNUP(self):
    try:
    # 1. Navigate to http://localhost:8000
    self.driver.get("http://localhost:8000/")
    self.driver.set_window_size(1680, 1025)

    # 2. Click the Sign Up button
    self.driver.find_element(By.LINK_TEXT, "Sign Up").click()

    # 3. Fill the sign-up form
    self.driver.find_element(By.ID, "id_email").send_keys("some_email@gmail.com")
    self.driver.find_element(By.ID, "id_password1").send_keys("as;dlfjkasj4asdf")
    self.driver.find_element(By.ID, "id_first_name").send_keys("Bill")
    self.driver.find_element(By.ID, "id_last_name").send_keys("asdfkj")
    self.driver.find_element(By.ID, "id_terms_agreement").click()
    self.driver.find_element(By.CSS_SELECTOR, ".btn").click()

    # 4. Navigate to the next section
    self.driver.find_element(By.CSS_SELECTOR, ".nav-item:nth-child(2) .is-hidden-tablet-only").click()

    # 5. Wait for the first iframe and switch to it
    WebDriverWait(self.driver, 10).until(
    EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe"))
    )

    # 6. Interact with the pricing table in the iframe
    WebDriverWait(self.driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, ".PriceColumn"))
    ).click()
    self.driver.find_element(By.CSS_SELECTOR, ".Button").click()

    # 7. Switch back to default content
    self.driver.switch_to.default_content()

    # 8. Wait for the next iframe (payment iframe) and switch to it
    WebDriverWait(self.driver, 10).until(
    EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe"))
    )

    # 9. Fill in the payment details
    self.driver.find_element(By.ID, "email").send_keys("some_email@gmail.com")
    self.driver.find_element(By.ID, "cardNumber").send_keys("4242 4242 4242 4242")
    self.driver.find_element(By.ID, "cardExpiry").send_keys("09 / 34")
    self.driver.find_element(By.ID, "cardCvc").send_keys("123")
    self.driver.find_element(By.ID, "billingName").send_keys("MAX")

    # 10. Click the submit button
    WebDriverWait(self.driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, ".SubmitButton-IconContainer"))
    ).click()

    except Exception as e:
    print(f"An error occurred: {e}")

    finally:
    self.driver.quit()

    Continue reading...

Compartilhe esta Página