简体   繁体   中英

Selenium send keys sends text twice even after clearing

I'm trying to login to an application and hence trying to send username and password. Steps that I'm following

  1. I'm identifying the field/waiting for the element to be clickable
  2. clear any existing value in the field
  3. send_keys(text)
  4. wait for 1 sec to redo the operation for next field

Actual result -

  1. Field is identified
  2. Username is entered fully (let's assume it is 'abc@gmail.com'
  3. Within a fraction of second, value is cleared and only first char of the text is re-entered ('a') and moves to next field password. This happens only for username field.

My code -

try: WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable(locator)) element = self.driver.find_element(*locator)

    except NoSuchElementException:
        log.error("Element not found {0}".format(locator))
        pytest.fail("Unable to find element. Please check locator {0}".format(locator))

    except Exception as error:
        log.error("Unknown exception error {0}".format(error))
        raise

    if text is None or text == "":
        log.error("Type function cannot accept NULL value to enter for element {0}".format(locator))
        raise TypeError("Type function cannot accept NULL value to enter for element {0}".format(locator))
    else:
        element.clear()
        element.send_keys(text)
        time.sleep(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM