我有一个下拉日历,我需要使用Selenium从中选择一个日期。 我正在使用python作为我的脚本语言。我也是这种硒的新手。
答案 0 :(得分:1)
对于以下HTML:
<select id="edit-birthday-day" class="form-select" name="birthday[day]">
<option selected="selected" value="">-</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
使用您可以在Python中使用以下脚本:
sel.select("id=edit-birthday-day", "label=2")
select ( selectLocator,optionLocator )
Select an option from a drop-down using an option locator.
Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.
label=labelPattern
matches options based on their labels, i.e. the visible text. (This is the default.)
label=regexp:^[Oo]ther
value=valuePattern
matches options based on their values.
value=other
id=id
matches options based on their ids.
id=option1
index=index
matches an option based on its index (offset from zero).
index=2
If no option locator prefix is provided, the default behaviour is to match on label.
Arguments:
selectLocator - an element locator identifying a drop-down menu
optionLocator - an option locator (a label by default)