【问题标题】:Python selenium select drop-down invisible (style =“display: none;”) elementPython selenium 选择下拉不可见 (style =“display: none;”) 元素
【发布时间】:2022-01-03 15:42:49
【问题描述】:

我正在尝试使用 python selenium 从下拉栏中选择一个元素,并选择 start_date 和 end_date。请找到网址:

<select title="drop_down" name="sType1" class="single_select2" style="display: none;" id="single_select_2">
<option value="">choice</option>
","
<option value="2101">issuance</option>
","
<option value="2701">listing</option>
","
</select>

我使用代码:

driver.get('http://www.sse.com.cn/disclosure/bond/announcement/npcorporate/')
driver.implicitly_wait(20)
s1 = Select(driver.find_element_by_id('single_select_2'))
driver.implicitly_wait(20)
s1.select_by_value('2101')
driver.find_element_by_id('btnQuery').click()

但是网站说:

ElementNotInteractableException: element not interactable: Element is not currently visible and may not be manipulated' how could I make it visible and able to select it?

而且我不知道如何将我的代码用于选择日期。有可能吗?

任何帮助将不胜感激!

【问题讨论】:

  • 哪一行出错了?
  • 您发送的页面没有 id=single_select_2 的元素,即使等待了很长时间。
  • 您好,感谢您的帮助,抱歉我放错了链接,现在我更新了,应该没问题http://www.sse.com.cn/disclosure/bond/announcement/npcorporate/跨度>

标签: python selenium selenium-webdriver select drop-down-menu


【解决方案1】:

与您共享的&lt;select&gt; 元素的HTML 包含属性style="display: none;"。大概,

  • 这不是您想要的元素,或者
  • 只有在尝试与之交互之前采取某些操作后,该元素才会可见。

否则Selenium 将无法关注 &lt;select&gt; 元素以与其交互。


参考

您可以在以下位置找到一些相关的详细讨论:

【讨论】:

  • 感谢您的帮助!我可以看到问题是什么,但仍然不知道解决方案..
【解决方案2】:
  • 使用 find_element(By.XPATH, drag_and_drop_xpath)
  • 检查 css 样式的可见性
  • 如果没有或不可见,添加可见性:可见;
  • 然后你可以看到可见的下降

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 2018-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多