【发布时间】:2019-12-30 07:16:55
【问题描述】:
我们如何先选择自动隐藏值选项,然后再选择需要的选项? 我的 HTML 文件如下:
在选择域之前:
div class="col-xs-12">
<label class=" required-field" for="Domain">Domain</label>
<select autocomplete="off" class="form-control select2-hidden-accessible valid" data-val="true" data-val-required="The 'Domain' field is required." id="Domain" name="Domain" tabindex="-1" aria-hidden="true" aria-describedby="Domain-error" aria-invalid="false">
<option value="">Select a domain...</option>
</select><span class="select2 select2-container select2-container--bootstrap select2-container--below select2-container--focus" dir="ltr" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-Domain-container"><span class="select2-selection__rendered" id="select2-Domain-container" title="Select a domain...">Select a domain...</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
<span class="field-validation-valid text-danger" data-valmsg-for="Domain" data-valmsg-replace="true"></span>
</div>
域名选择后:
<select autocomplete="off" class="form-control select2-hidden-accessible" data-val="true" data-val-required="The 'Domain' field is required." id="Domain" name="Domain" tabindex="-1" aria-hidden="true"><option value="">Select a domain...</option>
<option value="ABC.abc.com">ABC.abc.com</option></select>
<span class="select2 select2-container select2-container--bootstrap select2-container--below select2-container--focus" dir="ltr" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-Domain-container"><span class="select2-selection__rendered" id="select2-Domain-container" title="ABC.abc.com">ABC.abc.com</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
当我们启动网站时,它将显示域名下拉列表和“选择域”选项值。如果我选择“选择域”选项,将显示实际域名。(意味着在我选择选择域选项之前,不会显示有效的域名列表)
我是 selenium 新手,所以我尝试使用 find_element_by_id 和可见文本选项选择选项
我尝试了下面的 python 代码。但它不起作用。
select_element = Select(driver.find_element_by_id('Domain'));
print ([o.text for o in select_element.options])
select_element.select_by_visible_text('Select a domain...');
select_element1 = Select(driver.find_element_by_id('Select a domain...'));
select_element.select_by_value('XYZ.xyz.com')
wait = WebDriverWait(driver, 10 )
print('success')
我需要选择如下顺序:
- 选择域按钮。
接下来我需要选择自动隐藏文本“选择域...”选项值。然后将显示域值。 (注意:Utill Select a Domain... 选项实际域名未列出) (有时即使我选择选择域自动隐藏域列表不立即列出的另一个重要点 可能需要等待一段时间)
加载域列表的等待时间
- 在那选择(下拉列表)“ABC.abc.com”域值
- 输入登录用户名
- 输入密码
- 连接页面。
如果有人共享 Python 的完整代码,则被占用
【问题讨论】:
标签: python selenium selenium-webdriver