JimClayton
JimClayton

Reputation: 131

python and selenium send keys

Im trying to add input to a text box when i do try it doesn't find the element and it gives an error i don't know if im selecting the right element this is what i have so far

Traceback (most recent call last):
  File "./fl_bot.py", line 22, in <module>
    ui.WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.ID, "#billFirstName")))
  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:

the code abouve is the error message im getting

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


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

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()
checkout = browser.get('https://www.footlocker.com/shoppingcart/default.cfm?sku=')
checkoutbutton = browser.find_element_by_css_selector('#cart_checkout_button').click()
ui.WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.ID, "#billFirstName")))
browser.find_element_by_id("#billFirstName").send_keys(Keys.RETURN)

every time it makes it to the end of the script it dosent type and it just stops

[1]: https://www.footlocker.com/checkout/?uri=checkout this is the page im trying to check out on

Upvotes: 0

Views: 6254

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193108

The FIRST NAME is a mandatory field to be filled up, so instead of send_keys(Keys.RETURN) try to send some text as follows along with the expected_condition as element_to_be_clickable :

ui.WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='billFirstName']")))
browser.find_element_by_xpath("//input[@id='billFirstName']").click()
browser.find_element_by_xpath("//input[@id='billFirstName']").clear()
browser.find_element_by_xpath("//input[@id='billFirstName']").send_keys("user_first_name")

Upvotes: 1

Related Questions