【发布时间】:2019-12-23 10:57:00
【问题描述】:
我使用 selenium 和 python 编写测试。下拉列表有问题。
我尝试使用直接点击和 javascript executescript 方法,但它们都不起作用。我使用 selenium IDE 来查找 id、css、xpath 等。所以有多个选项,我都尝试了。
#select_btn = self.driver.find_element_by_css_selector("#select2-2v7k-container")
#select_btn = self.driver.find_element_by_css_selector(".col-md-12")
#select_btn = self.driver.find_element_by_id("select2-2v7k-container")
#select_btn = self.driver.find_element_by_id("select2-t2zd-container")
select_btn = self.driver.find_element_by_xpath("//span[@id='select2-2v7k-container']")
self.driver.execute_script("arguments[0].click();", select_btn)
#select_btn.click()
这里是元素部分(它是内部产品,所以没有公共网址)
<span _ngcontent-c3="" class="col-md-9 col-sm-8 col-xs-8">
<dashboard-saved-reports-select-component _ngcontent-c3="" _nghost-c5=""><select _ngcontent-c5="" aria-hidden="true" class="col-md-12 col-sm-12 col-xs-12 form-control select2-hidden-accessible" style="width: 100%" tabindex="-1">
<option _ngcontent-c5="" value="-1">Select A saved Report</option>
<optgroup _ngcontent-c5="" label="Reports 1">
<!----><option _ngcontent-c5="" value="447">options1
</option><option _ngcontent-c5="" value="457">options2
</option>
</optgroup>
<optgroup _ngcontent-c5="" label="Reports 2">
<!----><option _ngcontent-c5="" value="1020">options1
</option><option _ngcontent-c5="" value="1013">option2
</option>
</optgroup>
<optgroup _ngcontent-c5="" label="Reports 3">
</option><option _ngcontent-c5="" value="1035">denemeee
</option><option _ngcontent-c5="" value="1033">deneme-rapor
</option>
</optgroup>
<optgroup _ngcontent-c5="" label="Reports 4">
<!----><option _ngcontent-c5="" value="1032">dasd
</option><option _ngcontent-c5="" value="1025">deneeeeee
</option><option _ngcontent-c5="" value="1014">deneme
</option>
</optgroup>
</select><span class="select2 select2-container select2-container--default 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="-1" aria-labelledby="select2-cawo-container">
<span class="select2-selection__rendered" id="select2-cawo-container" title="Select A saved Report">Select A saved Report</span>
<span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span>
<span class="dropdown-wrapper" aria-hidden="true"></span></span>
</dashboard-saved-reports-select-component>
</span>
是否有其他方法或解决方法来检测和打开下拉列表。我找到了一些 javascript 方法来制作可见的下拉菜单,但它没有用。
【问题讨论】:
-
能不能加个html或者更好的分享一下url。
-
对不起,这是一个内部产品,所以没有公共网址。
-
在您提供的代码 sn-p 中,没有 ID 为
select2-2v7k-container的 span 标签。另外,如果你想打开一个下拉列表,你需要点击select标签 -
我从 Selenium IDE 中获取了 id、xpath、css 等,并直接从页面中输入了代码。不知道为什么不一样
-
你检查过 iframe 里面的下拉菜单吗?
标签: python selenium jquery-select2