gpt4 book ai didi

python - 如何使用 Selenium 从下拉日历中选择日期

转载 作者:太空宇宙 更新时间:2023-11-04 06:26:41 37 4
gpt4 key购买 nike

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

最佳答案

对于以下 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)

关于python - 如何使用 Selenium 从下拉日历中选择日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7537464/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com