我有点小问题。我正在写一个自动测试,它必须转到网页,输入一些关键字进行搜索,然后转到高级搜索选项,从列表中选择一个并进行搜索。关键是,我完全不知道如何在列表中定位元素。它看起来像这样:http://www.e-podroznik.pl/public/searcherFinal.do。如果你点击“więcej opcji”,你会看到关于旅程的选项列表。我的问题:如何使用PythonSelenium在这个扩展的“więcej opcji”列表中定位元素?我已经尝试了所有的方法,从find_element_by*到执行_脚本,都没用。我会遇到诸如“无法定位元素”、“不允许复合”等错误
HTML:
<div class="advanced-searcher dNone more-options" style="display: block;">
<label class="lblDepartureArrival"></label>
<label class="lblRadio frmButtonFlat lblDeparture"></label>
<label class="lblRadio frmButtonFlat lblDeparture"></label>
<span class="lblOmmit"></span>
<label class="lblCaptionCarrierType"></label>
<label class="lblCarrierType lblCheckbox frmButtonFlat carrierType-bus"></label>
<label class="lblCarrierType lblCheckbox frmButtonFlat carrierType-rail"></label>
<label class="lblCarrierType lblCheckbox frmButtonFlat carrierType-aut"></label>
<label class="lblCarrierType lblCheckbox frmButtonFlat carrierType-city"></label>
<label class="lblCaptionJourneyMode"></label>
<span class=""></span>
<span class=""></span>
<span class=""></span>
<label class="lblSort">
<span class="fldCaption">
Sortuj według:
</span>
<span class="fldContainer">
<select id="sortTypeV_1399324651976" name="formCompositeSearchingResults.formCompositeSearcherFinalH.sortTypeV" style="display: none;">
<option selected="selected" value="departure"></option>
<option value="time"></option>
<option value="price"></option>
</select>
<span class="frmDropdown"></span>
</span>
</label>
<a class="lnkSwitchSearcherType" title="Wyszukiwarka zaawansowana" href="/public/searcher.do?method=task&advanced=false"></a>
</div>
我特别需要扩展列表:
^{pr2}$这不起作用:
def do_the_advanced_search(self):
self.driver.find_element_by_xpath('//*[@id="frm_1399323992507"]/fieldset/div/div[2]/label[3]').click()
time.sleep(3)
这都不是:
self.driver.execute_script("document.getElementById('sortTypeV_1399324651976').style=='display: inline block';")
谢谢你的帮助。在
要展开包含下拉列表的部件,可以使用以下命令:
然后可以使用
^{pr2}$execute_script
设置值:select
本身是通过style=display:none;
隐藏的,因此不能直接操作它。在相关问题 更多 >
编程相关推荐