Issue
This is question follows another question I asked earlier
I am trying to use Python and Selenium to arrive at a page and enter Credit Card data. Unlike the earlier question where the field had dynamic properties, this field has a static name, meaning I can find the element by name, and input some data, it seems I am missing something big here. Here are the page details:
<input type="tel" id=cc-yN0P6v-14" autocomplete="off" name="txtCrdtCrdNum" class="a-input-text">
and my selenium code looks like this
objCrdNumber = driver.find_element_by_name('txtCrdtCrdNum')
objCrdNumber.send_keys(UserData.CrdtCrdNumber)
I get the error message
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
That's when I realised the input in of type tel. I wonder what that has got to do with anything. But I am stumped out of this.
Update
A big thank you to @Prophet. Walked the extra mile and walked along with me till the issue was resolved. We were missing a iFrame that was not visible in the area we were looking.
Solution
ElementNotInteractableException
means that you trying to access an element that is currently not interactable.
This can be caused by several causes.
- Element is not visible since it is out of the view.
- Element is still not fully rendered.
- Some other element is currently covering this element.
maybe something other, but similar to the above.
Since I can't know what causes your problem in your specific case you can try one of the following and it should work.
- To bring the element into view try this:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
objCrdNumber = driver.find_element_by_name('txtCrdtCrdNum')
actions.move_to_element(objCrdNumber).build().perform()
time.sleep(0.5)
objCrdNumber.send_keys(UserData.CrdtCrdNumber)
- to wait for the element is fully rendered try this:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.NAME, "txtCrdtCrdNum"))).send_keys(UserData.CrdtCrdNumber)
UPD
Your element is inside iframe.
You have to switch to that iframe in order to access elements inside it.
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@class,'secure')]"))
When finished with that form don't forget to switch to the default content with
driver.switch_to.default_content()
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.