I am trying to use selenium to send credit card info onto a site, and each element is contained in a separate iframe tag in the HTML. For example, the box to enter a credit card number is contained in the first iframe tag, and the card holder name is contained in the second iframe, and so on, and so forth. I am able to access the first iframe tag, and send the credit card number into the box, however I an unable to locate the cardholder name iframe tag, and thus cannot send the keys to enter a cardholder name. I'm wondering if there is a way to specifically search for the second (or an arbitrary number other than the first element) iframe tag with webdriver.
Here is the code I used:
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
cc = driver.find_element_by_id("number")
cc.send_keys(credit_card_number)
This correctly found the first iframe tag which contains the field to enter a card number, and sent the appropriate keys
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
driver.find_element_by_id("name").send_keys(cc_name)
This resulted in the following error: Message: no such element: Unable to locate element:{"method":"tag name","selector":"iframe"}
