如何单击按钮并使用selenium选择值?

h7wcgrx3  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(477)

我需要单击一个“用户列表”按钮,并需要选择“li”标记中可用的值。当我单击按钮时,我将获得类似下拉列表值的值。
我尝试使用selectbyvalue、selectbyindex等下拉选项。但是它抛出的错误为“element本应为“select”,但为“span”

<div class="dropbutton-wrapper dropbutton-multiple">
   <div class="dropbutton-widget">
      <ul class="dropbutton dropbutton--multiple dropbutton--extrasmall">
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-list-view" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-list-view" name="field_flexible_below_list_view_Sum_more" value="User List"></li>
         <li class="dropbutton-toggle"><button type="button"><span class="dropbutton-arrow"><span class="visually-hidden">List Sumitional actions</span></span></button></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-full-text-area" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-full-text-area" name="field_flexible_below_full_text_area_Sum_more" value="Sum Full text area"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-linked-image" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-linked-image" name="field_flexible_below_linked_image_Sum_more" value="Sum Image"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-video" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-video" name="field_flexible_below_video_Sum_more" value="Sum Video"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-image-grid" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-image-grid" name="field_flexible_below_image_grid_Sum_more" value="Sum Image grid"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-slideshow" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-slideshow" name="field_flexible_below_slideshow_Sum_more" value="Sum Slideshow"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-feed" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-feed" name="field_flexible_below_feed_Sum_more" value="Sum Feed"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-list-of-links" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-list-of-links" name="field_flexible_below_list_of_links_Sum_more" value="Sum List of links"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-call-to-action" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-call-to-action" name="field_flexible_below_call_to_action_Sum_more" value="Sum Call to action (OLD)"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-featured-article" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-featured-article" name="field_flexible_below_featured_article_Sum_more" value="Sum Featured article"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-social-link" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-social-link" name="field_flexible_below_social_link_Sum_more" value="Sum Social link"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-bio-box" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-bio-box" name="field_flexible_below_bio_box_Sum_more" value="Sum Bio box"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-success-story" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-success-story" name="field_flexible_below_success_story_Sum_more" value="Sum Success story"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-specification" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-specification" name="field_flexible_below_specification_Sum_more" value="Sum Specification"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-widget" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-widget" name="field_flexible_below_widget_Sum_more" value="Sum Widget"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-block" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-block" name="field_flexible_below_block_Sum_more" value="Sum Block"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-embedded-view" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-embedded-view" name="field_flexible_below_embedded_view_Sum_more" value="Sum Embedded view"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-thymeleaf-template" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-thymeleaf-template" name="field_flexible_below_thymeleaf_template_Sum_more" value="Sum Thymeleaf Template"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-columns-two" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-columns-two" name="field_flexible_below_columns_two_Sum_more" value="Sum Columns"></li>
         <li class="dropbutton__item dropbutton__item--extrasmall dropbutton-action secondary-action"><input class="field-Sum-more-submit button--small button js-form-submit form-submit" data-drupal-selector="edit-field-flexible-below-Sum-more-Sum-more-button-audio" formnovalidate="formnovalidate" type="submit" id="edit-field-flexible-below-Sum-more-Sum-more-button-audio" name="field_flexible_below_audio_Sum_more" value="Sum Audio"></li>
      </ul>
   </div>
</div>

附上的截图供参考

hts6caw3

hts6caw31#

你试过直接点击他们吗?
像这样单击下拉列表:

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='dropbutton-widget']"))).click()

然后单击以下任何选项:

wait.until(EC.element_to_be_clickable((By.XPATH, "//li[@value='Sum Slideshow']
"))).click()

进口:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

相关问题