2011-09-24 94 views
2

我有一个下拉日历,我需要使用硒从中选择一个日期。 我使用Python作为我的脚本语言。我也是这个硒的新手。如何从使用硒的下拉日历中选择日期

+2

能否请您发布你需要选择下拉日历的HTML源代码?准确的答案需要准确的信息:) –

+0

rit现在我不能访问application.if我得到我会发布。 – Sirga

回答

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") 

请同时参阅Selenium Documentation

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) 
+0

在这种情况下,sel对象是什么? WebDriver还是......?谢谢! – kiminoa

相关问题