1

I am coding a bot for www.kith.com I have gotten past the card number and when I use the last 10 lines of code(name on card, expiration, security code)... I get this error,

"raise TimeoutException(message, screen, stacktrace)

TimeoutException'

before I added webdriver wait the code I was getting was init uses 3 arguments but 2 were given or something like that I'm relatively new to coding so this has kinda been a challenge.

    code: 
        driver = webdriver.Chrome(executable_path=r'C:\webdrivers\Chromedriver.exe')
        driver.get(str(url))
         
        #size
        driver.find_element_by_xpath('//div[@data-value="S"]').click()
        
        #ATC
        driver.find_element_by_xpath('//button[@class="btn product-form__add-to-cart"]').click()
        time.sleep(6)
        
        #checkout
        driver.find_element_by_xpath('//button[@class="btn ajaxcart__checkout"]').click()
        time.sleep(3)
        
        #email
        driver.find_element_by_xpath('//input[@placeholder="Email"]').send_keys('example@gmail.com')
        
        #first
        driver.find_element_by_xpath('//input[@placeholder="First name"]').send_keys('first')
        
        #last
        driver.find_element_by_xpath('//input[@placeholder="Last name"]').send_keys('last')
        
        #address
        driver.find_element_by_xpath('//input[@placeholder="Address"]').send_keys('address')
        
        #city
        driver.find_element_by_xpath('//input[@placeholder="City"]').send_keys('town')
        
        #zip
        driver.find_element_by_xpath('//input[@placeholder="ZIP code"]').send_keys('99999')
        
        #phone number
        driver.find_element_by_xpath('//input[@placeholder="Phone"]').send_keys('9999999999' + u'\ue007')
        time.sleep(5)
    
        #continue to payment
        driver.find_element_by_xpath('//button[@type="submit"]').click()
        time.sleep(8)
        
       #card number 
        driver.switch_to.frame(driver.find_element_by_class_name("card-fields-iframe"))
        driver.find_element_by_id("number").send_keys('1234')
        driver.find_element_by_id("number").send_keys('1234')
        driver.find_element_by_id("number").send_keys('1234')
        driver.find_element_by_id("number").send_keys('1234')
        
        #payment   
        Exception(TimeoutException)
        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Name on card')]")))
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-current-field]"))).send_keys('john')
        driver.switch_to.default_content()
    
        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Expiration date')]")))
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-current-field]"))).send_keys('11/23')
        driver.switch_to.default_content()
    
        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Security code')]")))
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-current-field]"))).send_keys('123')
        driver.switch_to.default_content()

any suggestions would mean a lot to me. StackOverflow has helped me a ton so far. <3

corrupt
  • 31
  • 1
  • 4

2 Answers2

2

Its look like you have issues with frames you are switching. Note as per your below line of code

 driver.switch_to.frame(driver.find_element_by_class_name("card-fields-iframe"))

You are inside frame card-fields-iframe, now as per below

 WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Expiration date')]")))

It will try to search for frame Expiration date inside card-fields-iframe. And so on for next two frames. I am not sure if your frames are cascaded like this. If these frames names on card, Expiry Date etc. are not inside each other, after performing your action please go to parent frame where all of these are tucked in.

driver.driver.switch_to.parent_frame()

Note : I am not sure which country you are doing your purchase. However I have done at my location (Singapore ) and able to click payment with below code. Please see for Singapore objects and frames are different from your location.

driver.get("https://kith.com/collections/mens-apparel/products/mc8g75300v8162-984")
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='Shop now']"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Add to Cart')]"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn ajaxcart__checkout']"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='I ACCEPT COOKIES']"))).click()
WebDriverWait(driver, 30).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"Intrnl_CO_Container")))
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '//div[contains(text(),"Order Summary")]')))

# Buyer Details

driver.find_element_by_xpath('//input[@placeholder="First Name"]').send_keys('first')
driver.find_element_by_xpath('//input[@placeholder="Last Name"]').send_keys('last')
driver.find_element_by_xpath('//input[@placeholder="Email"]').send_keys('example@gmail.com')
driver.find_element_by_id('CheckoutData_BillingAddress1').send_keys('address')
driver.find_element_by_id('BillingCity').send_keys('town')
driver.find_element_by_id('BillingZIP').send_keys('999999')
driver.find_element_by_xpath('//input[@placeholder="Mobile Phone"]').send_keys('9999999999' + u'\ue007')



# card number

driver.switch_to.frame('secureWindow')
driver.find_element_by_id("cardNum").send_keys('5225517926810376')
month = Select(driver.find_element_by_id('cardExpiryMonth'))
year = Select(driver.find_element_by_id('cardExpiryYear'))
month.select_by_index(1)
year.select_by_index(4)
driver.find_element_by_id("cvdNumber").send_keys('124')

# Click on payment. Its not inside secure window Frame rather its under parent frame of it

driver.switch_to.parent_frame()
paybtn = driver.find_element_by_id('btnPay')
driver.execute_script("arguments[0].scrollIntoView();", paybtn)
paybtn.click()
rahul rai
  • 2,260
  • 1
  • 7
  • 17
  • in the lines month = Select(driver.find_element_by_id('cardExpiryMonth')) year = Select(driver.find_element_by_id('cardExpiryYear')) it says select is undefined... any ideas? – corrupt Aug 21 '20 at 04:08
  • Can you check if element you are trying to identify with driver.find_element_by_id('cardExpiryYear'), is a select type tab ? If not then select class wont on that. – rahul rai Aug 21 '20 at 04:12
0

Remove this line

Exception(TimeoutException)

your code will work you don't need to add this line

you are give timeout argument with WebDriverWait(driver, 10)

The 10 or what ever time you wish is time your script will wait until than

Haseeb Ahmed
  • 265
  • 3
  • 10
  • I already tried it without and I still got the same error – corrupt Aug 20 '20 at 05:56
  • Can you post full error message it's difficult to figure it out without full error – Haseeb Ahmed Aug 20 '20 at 06:01
  • It wont help, although this line if code has no meaning in this context, but this is not gving exception. He is getting exception because he has not navigated to his frame correctly. Please see in answer section. I have explained it. – rahul rai Aug 20 '20 at 06:40
  • @rahul I'm gonna try that i appreciate it a lot <3 – corrupt Aug 20 '20 at 14:31