我一直在尝试选择一个下拉菜单,但我注意到它的XPath和ID每次都会改变,所以它可能是动态的。如何在这种类型的条件下捕获元素的正确路径?我们正在尝试将CSV放在下拉菜单中
<div class="form-group">
<label>Report Type</label>
<div>
<select data-dom-uuid="" tabindex="-1" data-name="Report Type" data-input-id="attached_report_type" data-type="select" class="editor-input select2-hidden-accessible" aria-label="Report Type" aria-hidden="true">
<option value="csv">CSV</option>
<option selected="selected" value="db">db</option>
<option value="pdf">PDF</option>
</select><span class="select2 select2-container select2-container--db select2-container--below select2-container--open" dir="ltr" style="width: 100px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="true" tabindex="11" aria-labelledby="select2-bka6-container" aria-owns="select2-bka6-results" aria-activedescendant="select2-bka6-result-vwdq-db"><span class="select2-selection__rendered" id="select2-bka6-container" title="db">db</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
</div>
</div>
我们已经尝试过这些选项,但都不起作用。
#driver.find_element_by_xpath("/html/body/span/span").click()
#driver.find_element_by_xpath("//*[@id=select2-7h5y-result-ycb2-csv]").click()
#driver.find_element_by_id("id=select2-mrbe-container]").click()
#driver.find_element_by_xpath("/html/body/section[3]/section[3]/section/form/div[1]/div/div/div[1]/section/div[3]/div[1]/div[1]/div[2]/div[6]/div[1]/div/select").click()
select = Select(driver.find_element_by_xpath("//select[@data-input-id='attached_report_type']"))
select.select_by_value("CSV").click()
发布于 2019-06-26 08:31:50
请使用ByTagName
driver.findElement(By.tagName("select"));
https://stackoverflow.com/questions/56754226
复制相似问题