Reputation: 2355
I'm trying to use send_keys
to fill a field and in the same time, store this value in a variable. When I run this code, the text of the variable is not printed.
locators.py
from selenium.webdriver.common.by import By
class CreateNewContractor(object):
FIRST_NAME = (By.ID, "id_0-first_name")
pages.py
from locators import *
class CreateNewContractor1(Page):
def fill_contractor(self):
email = self.find_element(*CreateNewContractor.FIRST_NAME).send_keys("Hello")
email.text
print email
How can I store and print the text filled in the email variable?
Upvotes: 1
Views: 3568
Reputation: 474171
The email
variable would get the value None
- this is what send_keys()
method returns.
Instead, you can simply keep the text in a variable:
text = "hello"
self.find_element(*CreateNewContractor.FIRST_NAME).send_keys(text)
print(text)
Or, if you want to actually get the value of the input
, use get_attribute()
method:
elm = self.find_element(*CreateNewContractor.FIRST_NAME)
elm.send_keys("hello")
print(elm.get_attribute("value"))
Upvotes: 4