使用Selenium从下拉菜单中选择项目

时间:2018-09-12 11:56:19

标签: python selenium selenium-webdriver selenium-chromedriver

我需要使用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:消息:   元素不可见

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

  

Selenium.common.exceptions.ElementNotVisibleException:消息:   元素不可见:元素当前不可见并且可能不可见   操纵

无论我尝试什么,都会得到不可见的元素

0 个答案:

没有答案