0

I am trying to send keys to an element but it is not working.

Element looks like this. Unable to send keys to all three.

Below is the code:

input id="creditCardNumber" name="creditCardNumber" type="tel" tabindex="1" data-shortname="cc" maxlength="24" class="cc-input ncss-input pt2-sm prl4-sm prl5-md pb2-sm" placeholder="Number" onautocomplete="off" value=""

I was using this to send keys:

driver.find_element_by_xpath('//*[@id="creditCardNumber"]').send_keys('0000')

driver.find_element_by_xpath('//input[@placeholder="Number"]').send_keys('0000')

Gives me an error as if element is not available, although I use a long enough time.sleep.

Error Received:

driver.find_element_by_xpath('//input[@placeholder="Number"]').send_keys('0000') File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element 'value': value})['value'] File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute self.error_handler.check_response(response) File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@placeholder="Number"]"}
(Session info: chrome=64.0.3282.140) (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.12.2 x86_64)

12
  • 1
    Please read why a screenshot of HTML or code or error is a bad idea. Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. Commented Feb 13, 2018 at 19:44
  • apologies, updated. Commented Feb 13, 2018 at 19:46
  • can you paste the traceback? what exact error are you getting Commented Feb 13, 2018 at 19:47
  • updated with traceback @Satish Commented Feb 13, 2018 at 19:50
  • can you place a explicit wait before finding the element and then try again selenium-python.readthedocs.io/waits.html Commented Feb 13, 2018 at 19:53

1 Answer 1

2

I signed up for nike to look up the creditCardNumber field, it is under an iframe tag. Switch to that iframe and then search for the element

<iframe sandbox="allow-scripts allow-same-origin" class="credit-card-iframe mt1 u-full-width" src="https://paymentcc.nike.com/services?id=0971b459-934f-4c0e-bdd1-6b5808a77eb1" frameborder="0" scrolling="no"></iframe>

Code:

driver.switch_to.frame(driver.find_element_by_css_selector('iframe[class="credit-card-iframe mt1 u-full-width"]'))
driver.find_element_by_id('creditCardNumber').send_keys('0000')

let me know if this works

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

Comments

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.