Reputation: 23
I'm currently trying out Selenium for Python to do some web automation. I got stuck a the checkout where you have to enter your credit card data. I'm aware that I have to switch to iFrame to locate the input box. But I was never able to switch the frame. I tried it for ID or for example for this:
time.sleep(4)
frame = self.driver.find_element_by_xpath("//iframe[@name= '__privateHeidelpayFrame--heidelpay-holder-iframe-1616489954834']")
self.driver.switch_to.frame(frame)
name_input = self.driver.find_element_by_id("card-holder")
name_input.clear()
name_input.send_keys(credit_card.NAME)
I'm always getting "Unable to locate element : {"method":"xpath","selector":"//iframe[@name= '__privateHeidelpayFrame--heidelpay-holder-iframe-1616489954834']"}".
I added a pic from the Source Code. Source Code from the Webpage
I'm thankful for any advise! Best, Jannic
Upvotes: 2
Views: 719
Reputation: 33384
Possibly id & name attribute is dynamic.
Try with starts-with()
or use other attribute like class to identify the iframe.
frame = self.driver.find_element_by_xpath("//iframe[starts-with(@name, '__privateHeidelpayFrame--heidelpay-holder-iframe-')]")
self.driver.switch_to.frame(frame)
OR
frame = self.driver.find_element_by_xpath("//iframe[@class='heidelpayUIIframe']")
self.driver.switch_to.frame(frame)
Upvotes: 1
Reputation: 572
Have you tried using a simpler API to find the iFrame?
Does
self.driver.find_element(By.NAME, "__privateHeidelpayFrame--heidelpay-holder-iframe-1616489954834'")
Return anything?
Upvotes: 0