[英]Select from a dropdown box without using the Select or Option tags: selenium python
我試圖從網絡上的下拉列表中選擇一個值,但 HTML 沒有任何 Select 或 Option 標簽。 列表的值在一個表中,而不是嵌入在代碼中。 我確實有能力在這個框中輸入文本,所以我想一個簡單的解決方案就是使用 .sendkeys(在網頁上,如果輸入的文本與下拉選項匹配,它可以工作),但我想 Python 不會讓你這樣做那個到組合框,因為我剛得到一個元素不可見的錯誤。 我找到了下面的鏈接,其中詳細介紹了如何與下拉列表交互,但“無選擇選項”部分只有 Java 和 Ruby 的示例。
下面是下拉框的檢查代碼。
我有哪些選擇?
<span class="custom-combobox">
<input title="" class="custom-combobox-input ui-widget ui-widget-content ui-corner-left ui-autocomplete-input" autocomplete="off">
<a tabindex="-1" class="ui-button ui-widget ui-button-icon-only custom-anchor custom-combobox-toggle ui-corner-right" role="button">
<span class="ui-button-icon ui-icon ui-icon-triangle-1-s">
</span><span class="ui-button-icon-space"> </span></a></span>
<span class="ui-button-icon-space"> </span>
剛剛為這個煩人的問題找到了一個非常簡單的解決方案,為了解決這個問題一直在四處尋找,在沒有 Select 類的情況下選擇下拉列表
# Find your dropdown element by the following, finds the element in the dropdown named BRA
Dropdown_Element = driver.find_element(By.XPATH, "//*[text()='BRA']").click()
# Store the ActionChains class inside the actions variable
actions = ActionChains(driver)
# Click on the element using the click(on_element=)
actions.click(on_element=Dropdown_Element)
time.sleep(2)
actions.perform()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.