Home > Software design >  Why is Selenium sometimes unable to send characters within input field without any error message?
Why is Selenium sometimes unable to send characters within input field without any error message?

Time:07-22

I'm using Selenium in python to webscrape. Most of the time when I use:

driver.find_element_by_xpath("//input[@placeholder='name']").send_keys("data")

it works but in some occasions it does not, and it has no error message:

Message:
Stacktrace:
Backtrace:
       Ordinal0 [0x00BBD953 2414931]
       Ordinal0 [0x00B4F5E1 1963489]
       Ordinal0 [0x00A3C6B8 837304]
       Ordinal0 [0x00A69500 1021184]
       Ordinal0 [0x00A6979B 1021851]
       Ordinal0 [0x00A96502 1205506]
       Ordinal0 [0x00A844E4 1131748]
       Ordinal0 [0x00A94812 1198098]
       Ordinal0 [0x00A842B6 1131190]
       Ordinal0 [0x00A5E860 976992]
       Ordinal0 [0x00A5F756 980822]
       GetHandleVerifier [0x00E2CC62 2510274]
       GetHandleVerifier [0x00E1F760 2455744]
       GetHandleVerifier [0x00C4EABA 551962]
       GetHandleVerifier [0x00C4D916 547446]
       Ordinal0 [0x00B55F3B 1990459]
       Ordinal0 [0x00B5A898 2009240]
       Ordinal0 [0x00B5A985 2009477]
       Ordinal0 [0x00B63AD1 2046673]
       BaseThreadInitThunk [0x7798FA29 25]
       RtlGetAppContainerNamedObjectPath [0x77BB7A9E 286]
       RtlGetAppContainerNamedObjectPath [0x77BB7A6E 238] ```

CodePudding user response:

To send a character sequence to an <input> element ideally you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='name']"))).send_keys("data")

Note: You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

CodePudding user response:

The only fields that can not be filled out are for credit card data and the code worked with those before, is it possible that it is somehow made impossible to reach them by webscraping?

  • Related