使用Selenium从下拉列表中选择项目

2024-10-02 20:30:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要使用Selenium从下面的下拉列表中选择Cars/data option array index=“5”:

<!-- Activity -->
<div class="field clearfix">
  <label for="infosActivity" class="aligned">Main activity</label>
  <div class="contentinput">
    <select id="infosActivity" name="shop_activity" class="chosen">
      <option value="0" style="font-weight: bold" selected="selected">Please choose your main activity</option>
      <option value="2" >Animals and Pets</option>
      <option value="3" >Art and Culture</option>
      <option value="4" >Babies</option>
      <option value="5" >Beauty and Personal Care</option>
      <option value="6" >Cars</option>
      <option value="0">Other activity...</option>
    </select>
  </div>
  <p class="userInfos aligned">Help us learn more about your store 
  so we can offer you optimal guidance and the best features for your business!</p>
</div>
<input value="full" name="db_mode" type="hidden" />

我试过以下方法:

1。driver.find_element_by_id("infosActivity").send_keys('Cars')=>;错误:

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

2.Select(driver.find_element_by_id("infosActivity")).select_by_visible_text('Cars')=>;错误:

Selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated

无论我尝试什么,我都会得到不可见的元素。你知道吗


Tags: anddividyourbyvaluenotelement