**Work on a program and want to get content written inside the dialog box Use Selenium chromedriver Python, I want to get the text written by the user Use the experiment to get the text text written into the text box of the Google search engine
search = browser.find_element_by_name ('q')
search.send_keys ("google search through python")
# t = browser.find_element_by_name ('q').text
#print (t) //Output: '' //string empty
#print (search.send_keys(Keys.RETURN)): Output: none
# search.send_keys (Keys.CONTROL, 'a')
# search.send_keys (Keys.CONTROL, 'c')
#t = search.send_keys (Keys.RETURN, 'v')
#print (t) //Output: None**
In HTML, the text of an element is (roughly speaking) the content found between its opening and closing tags:
<p>This is the text of a paragraph element.<p>
An <input>
element, however, doesn’t have any inner content. Instead, its value is stored in its value
attribute:
<input type="text" name="q" value="google search through python" />
This is why .text
always returns None
: no inner content means no text. Instead, you need to use .get_attribute("value")
:
search = browser.find_element_by_name("q")
search.send_keys("google search through python")
print search.get_attribute("value")