How to insert a value in a field Text using Selenium?

Gizelly

I can't insert a value in field text in html formulary using Selenium Python:

I have this HTML:

<div data-react-toolbox="input" class="_2dBwA"><input type="text" placeholder="Endereço de e-mail" class="_2WvFs" role="input"><span class="fT1WI"></span></div>

and this XPath:

(Copy Xpath) //*[@id="root"]/div/div[2]/div[2]/div/input

and this:

(Copy outerHTML) <input type="text" placeholder="Endereço de e-mail" class="_2WvFs" role="input">

I did it, but dont worked:

[In]: login_name = 'Cassandra'
[In]: insert_login_name = driver.find_element_by_xpath('//input[@id="root"]')
[In]: insert_login_name.send_keys(login_name);

[Out]: NoSuchElementException:  Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id="root"]"}

After entering the text in this text field, the result would be in html 'values' = 'Cassandra'

<div data-react-toolbox="input" class="_2dBwA"><input type="text" placeholder="Endereço de e-mail" class="_2WvFs _3QmiH" role="input" value='Cassandra'><span class="fT1WI"></span></div>

What can i do? I'm new in that. Thanks

DebanjanB

The desired element is a ReactJS enabled element so to send a character sequence with in the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-react-toolbox='input']>input[placeholder='Endereço de e-mail'][type='text']"))).send_keys(login_name)
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@data-react-toolbox='input']/input[@placeholder='Endereço de e-mail' and @type='text']"))).send_keys(login_name)
    
  • 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
    

Update

Seems it was a locale issue. Changing the value of placeholder attribute from Endereço de e-mail to E-mail address works perfecto.

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-react-toolbox='input']>input[placeholder*='mail'][type='text']"))).send_keys(login_name)
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@data-react-toolbox='input']/input[contains(@placeholder, 'mail') and @type='text']"))).send_keys(login_name)
    

Reference

You can find a relevant detailed discussion in:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to locate and insert a value in a text box (input) using Python Selenium?

How to get a specific value from column & insert it in field, when using selenium webdriver

How to get value from a disabled text field when the value is not present in ID or in any attribute using Java in Selenium WebDriver

How to insert a text into a div node using Selenium and Python

how to insert text field in the place of string in pdf using java

How to send text to the Email field using Selenium and Python

How to type some text in hidden field in Selenium WebDriver using Java

How to send text with in the username field within an iframe using Selenium VBA

How to replace default values in the text field using selenium python?

How to send text within the Username field using Python Selenium

How to insert and get the value of a dynamically created input field using javascript?

How to insert a value to created_at field using Query Builder

Setting a value in a text field using selenium. selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:

How to select a value from a lookup field using selenium webdriver

How to enter numeric value in input field using Python Selenium?

How to change the input field value using Selenium and Python

How to insert a field after check the value of a field

How to insert a specific value at the beginning of text in a Column using Excel VBA?

How to retrieve all elements text value present in the screen using selenium?

How to wait for text value to show using Selenium Python

How to extract the text of value attribute indside a tag using selenium

How to click a button using Selenium, via text or value?

How to click on dropdown by finding it's text or value using selenium in python?

How do I insert a simple value to a BLOB field using the INSERT INTO statement?

How do I get the value of text input field using JavaScript?

How do i get the value of text input field using react

How to insert text in smart textbox in selenium webdriver?

Insert into Input field in selenium

How to insert an icon in the beginning of a Material Text Field