0

im trying to iterate through a form to input values for each field. im using JSON to hold the values and a for loop to iterate through them

When the code is run i get an error message!

error message

Traceback (most recent call last):
  File "./fl_bot.py", line 35, in <module>
    ui.WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id="+info+"]")))
  File "/Library/Python/2.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

json

{
    "billFirstName":"rashawn",
    "billLastName":"doyley",
    "billAddress1":"11612 newburg st",
    "billPostalCode":"11412",
    "billCity":"jamaica",
    "billState":"ny",
    "billHomePhone":"7184139582",
    "billEmailAddress":"[email protected]"
}

code

from selenium.webdriver.support import ui
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import json
from pprint import pprint

def get_page(model, sku):
    url = "https://www.footlocker.com/product/model:"+str(model)+"/sku:"+ str(sku)+"/"
    return url

data = json.load(open('info.json'))

browser = webdriver.Firefox()

page=browser.get(get_page(277097,"8448001"))

browser.find_element_by_xpath("//*[@id='pdp_size_select_mask']").click()

shoesize = ui.WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a.grid_size:nth-child(8)')))

shoesize.click()

browser.find_element_by_xpath("//*[@id='pdp_addtocart_button']").click()

browser.get('https://www.footlocker.com/shoppingcart/default.cfm?sku=')

browser.find_element_by_css_selector('#cart_checkout_button').click()



for info , Value in data.items():
    ui.WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id="+info+"]")))

    browser.find_element_by_xpath("//input[@id="+info+"]").click()

    browser.find_element_by_xpath("//input[@id="+info+"]").clear()
    #print(info,Value)
    browser.find_element_by_xpath("//input[@id="+info+"]").send_keys(Value)

when i use a print statement to print out the elements that are being held in the info variable i get only 4 of the elements and in no particular order

billCity
billFirstName
billEmailAddress
billLastName
Traceback (most recent call last):
  File "./fl_bot.py", line 42, in <module>
    ele = ui.WebDriverWait(browser, 90).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='"+info+"']")))
  File "/Library/Python/2.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
2
  • Show info.json and error message Commented Feb 9, 2018 at 5:50
  • error message is in the top half and the json is added Commented Feb 9, 2018 at 6:32

1 Answer 1

1

The root cause is xpath incorrect, need to use single or double quote around id value.

"//input[@id="+info+"]" should be "//input[@id='"+info+"']"

Another possible risk is the page take long time to loading after click CHECKOUT button, 10 seconds is not enough. Increase 10 to 60 seconds.

for info, value in data.items():
    ele = ui.WebDriverWait(browser, 60)
        .until(EC.element_to_be_clickable((By.XPATH, "//input[@id='"+info+"']")))

    ele.click()
    ele.clear()
    ele.send_keys(value)

Only the first element will wait long time, the next element will take less than 2 seconds to find even you give max find time is 60 seconds, because the page loaded.

Sign up to request clarification or add additional context in comments.

4 Comments

it works partially part of the login form is not being filled in a whole way!
Traceback (most recent call last): File "./fl_bot.py", line 42, in <module> ele = ui.WebDriverWait(browser, 90).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='"+info+"']"))) File "/Library/Python/2.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
debug code print out "//input[@id='"+info+"']" , to see which element not found.
its only printing these out odly enough billCity billFirstName billEmailAddress billLastName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.