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
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
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)
You can find a relevant detailed discussion in:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments