0
votes

I am trying to make a python script that will make payment automatically on this site. I am able to get credit-card-number input but i can't access expirty month or CVV.

Code I tried
I used this to get credit card number field below

WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='braintree-hosted-field-number']")))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='number' and @id='credit-card-number']"))).send_keys("0000000000000000")

I used same thing to get Expiry month field, like this,

WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[@id="braintree-hosted-field-expirationMonth"]')))
WebDriverWait(browser, 60).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='expirationMonth' and @id='expiration-month']"))).send_keys("12/2024")

But this code don't work

So what I want is, I want to detect Expiration field and also CVV field, the method I used can't detect the field.

3
there no expirationmonth only expirationdate - PDHide

3 Answers

0
votes

if you switch to one iframe you have to swithc to default content before you can interact with another iframe outside the current iframe in which the code focus is use

WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='braintree-hosted-field-number']")))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='number' and @id='credit-card-number']"))).send_keys("0000000000000000")
browser.switch_to_default_content()
WebDriverWait(browser, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[@id="braintree-hosted-field-expirationMonth"]')))
WebDriverWait(browser, 60).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='expirationMonth' and @id='expiration-month']"))).send_keys("12/2024")
0
votes

Frame id was off and the xpath was also off cause no expirationMonth. Also switch to default content.

browser.get("https://www.audiobooks.com/signup")
wait = WebDriverWait(browser, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"braintree-hosted-field-number")))
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@class='number' and @id='credit-card-number']"))).send_keys("0000000000000000")
browser.switch_to.default_content()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "braintree-hosted-field-expirationDate")))
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@class='expirationDate' and @id='expiration']"))).send_keys("12/2024")
-1
votes

Try switch first, then catch the xpath Try to switch to the iframe first, then you can identify the column with xpath