1

I'm on a retailers web site and having trouble finding the CVV input field. Here's what I've tried.

searchXml = '//*[@id="payment-preferences"]/div[1]/fieldset/div[1]/div[2]/div[2]/input'
purchase = driver.find_element_by_xpath(searchXml)

Here's the error messages from the xpath search. I've also added several time.sleep() to slow down the script.

Traceback (most recent call last):
  File "Selenium_test.py", line 106, in <module>
    purchase = driver.find_element_by_xpath(searchXml)
  File "/Users/claybogusky/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Users/claybogusky/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "/Users/claybogusky/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/claybogusky/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="payment-preferences"]/div[1]/fieldset/div[1]/div[2]/div[2]/input"}
  (Session info: chrome=89.0.4389.114)

Thanks!!

DOM from page it shows an iFrame.

https://i.stack.imgur.com/nnAtY.jpg

Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
Clay
  • 11
  • 5
  • Added code tags to your question. Please do so yourself in the future. –  Apr 09 '21 at 13:44
  • The traceback shows that you have a web element instance in your variable `purchase` so one of your `purchase = driver.find...` returned a match. The traceback also shows the error is in `purchase.find_element_by_name('cvv')` and not in the `purchase = driver.find...` call. –  Apr 09 '21 at 13:46
  • You need to post more of your HTML. `input` elements do not have children so why are you trying `purchase.find_element_by_name('cvv')` which would look for a descendant of the `purchase` element with the `name="cvv"`? –  Apr 09 '21 at 13:49
  • yes, i coped the wring output. – Clay Apr 09 '21 at 14:48
  • "i coped the wring output." -- then edit your question and post the correct text. –  Apr 09 '21 at 15:13
  • updated the posting. Thanks! – Clay Apr 09 '21 at 18:23

2 Answers2

0

I am confused by your question as you are asking about a password field and also a search field above it. If all you need to do is input the password you can try:

purchase = driver.find_element_by_xpath("//input[@type='password']");
JD2775
  • 3,658
  • 7
  • 30
  • 52
  • Thanks for your reply! The field is actually a CVV input field but the XML path and the HTML say that the input type is 'password'. I tried your code above but had the same error. Somehow, this CVV input field is hiding very well!! – Clay Apr 09 '21 at 14:39
  • File "Selenium_test.py", line 101, in purchase = driver.find_element_by_xpath("//input[@type='password']") File "/Users/claybogusky/Library/Python/3.8/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath Unable to locate element: {"method":"xpath","selector":"//input[@type='password']"} – Clay Apr 09 '21 at 14:48
  • I think we need to see more of the HTML/DOM in your original post. It's possible this button is inside an iFrame or something similar that you need to switch to first. – JD2775 Apr 09 '21 at 14:52
  • I added a screen shot in the posting above. Thanks again. – Clay Apr 09 '21 at 18:24
  • There is an iframe at the top of the image above!! – Clay Apr 09 '21 at 18:27
  • This should get you sorted out: https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python – JD2775 Apr 09 '21 at 20:16
  • Thank you!! This led me to an answer. – Clay Apr 10 '21 at 14:35
0

The CVV is located in an iFrame so I needed to "enter" the iframe, search and send the CVV, and then return to the parent iFrame to complete the purchase. My CC is stored on the site under my profile so I didn't need to enter that information.

Here's the code.

enter CVV

time.sleep(20)

iframe = driver.find_element_by_xpath( '//*[@id="sppIframe"]')
driver.switch_to.frame(iframe)
searchXml = '//*[@id="payment-preferences"]/div[1]/fieldset/div[1]/div[2]/div[2]/input'
purchase = driver.find_element_by_xpath(searchXml)          
purchase.send_keys( v.cvv )
driver.switch_to.parent_frame()

time.sleep(10)
button_submit = '//*[@id="place-order-button"]'
placeOrderButton = driver.find_element_by_xpath(button_submit)   
Clay
  • 11
  • 5