-
Notifications
You must be signed in to change notification settings - Fork 142
PageSelect
虫师 edited this page Dec 1, 2018
·
4 revisions
Selenium所提供的下拉框并不太好用,为此selenium-page-object提供了PageSelect类。
例如有以下选择框。
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
使用方式如下:
from page_objects import PageSelect, PageObject, PageElement
from selenium import webdriver
class SelectPage(PageObject):
elm = PageElement(xpath="//select")
def test_select():
"""测试选择框的操作"""
dr = webdriver.Chrome()
page = SelectPage(dr)
page.get("http://www.xxxx.com")
PageSelect(page.elm, value="saab")
PageSelect(page.elm, index=2)
PageSelect(page.elm, text="Audi")
PageSelect
类第一个参数为select
标签的对象,后面可以选择不同的方式定义选项。
-
value 对应
value="volvo"
-
index 对应选项的索引,第1个选项,第2个选项...
-
text 对应
>Audi</option>