如何使用Selenium WebDriver按名称查找文本输入?
我是一名硒新手,只是想学习基础知识.我有一个简单的CherryPy Webapp,它以名字和姓氏作为输入:
I'm a selenium newbie and just trying to learn the basics. I have a simple CherryPy webapp that takes a first name and last name as input:
我的Web应用程序:
<p>
<label></label>
<input name="first_name"></input>
<br></br>
</p>
<p>
<label></label>
<input name="last_name"></input>
<br></br>
</p>
在我的python控制台中,我有:
In my python console I have:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://localhost:8080')
该页面在FF中可以很好地加载,但是我对如何将文本输入"first_name"和"last_name"文本框中感到有些困惑.我看到了一些示例,在这些示例中,您先执行inputElement = driver.find_element_by_id("n")
然后执行inputElement.send_keys('my_first_name')
之类的操作,但是我没有id ...只是一个name
.我需要向网页添加内容吗?谢谢!
The page loads fine in FF but I'm a little lost on how to get text into the 'first_name' and 'last_name' text boxes. I see examples where you do something like inputElement = driver.find_element_by_id("n")
and then inputElement.send_keys('my_first_name')
but I don't have an id...just a name
. Do I need to add stuff to my web page? Thanks!