如何 Return 来自 selenium 的文本?
How to Return the texts from selenium?
**正在做一个程序,想得到对话框里面写的内容
使用Selenium chromedriver Python,我想获取用户写的文字
使用实验获取Google搜索引擎
的文本框写入的文本文本
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**
在HTML中,元素的文本是(粗略地说)在其开始和结束标签之间找到的内容:
<p>This is the text of a paragraph element.<p>
但是,<input>
元素没有任何内部内容。相反,它的值存储在它的 value
属性中 :
<input type="text" name="q" value="google search through python" />
这就是为什么.text
总是returns None
:没有内容就没有文字。相反,您需要使用 .get_attribute("value")
:
search = browser.find_element_by_name("q")
search.send_keys("google search through python")
print search.get_attribute("value")
**正在做一个程序,想得到对话框里面写的内容 使用Selenium chromedriver Python,我想获取用户写的文字 使用实验获取Google搜索引擎
的文本框写入的文本文本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**
在HTML中,元素的文本是(粗略地说)在其开始和结束标签之间找到的内容:
<p>This is the text of a paragraph element.<p>
但是,<input>
元素没有任何内部内容。相反,它的值存储在它的 value
属性中 :
<input type="text" name="q" value="google search through python" />
这就是为什么.text
总是returns None
:没有内容就没有文字。相反,您需要使用 .get_attribute("value")
:
search = browser.find_element_by_name("q")
search.send_keys("google search through python")
print search.get_attribute("value")