【问题标题】:Element not Visible when trying to access Select Input Python Splinter尝试访问 Select Input Python Splinter 时元素不可见
【发布时间】:2018-07-24 08:08:30
【问题描述】:

我正在尝试使用 Python Splinter 在选择下拉列表中单击某些元素。

源代码(示例-原始选项值更多)为:

<div class="row form-group">
     <div class="col s12 m12 l6">
        <label>
        Zeitzone der Website
        </label>
        <div class="select-wrapper">
           <span class="caret">▼</span><input type="text" class="select-dropdown" readonly="true" data-activates="select-options-0388a2bc-2b5c-c534-8870-fc41b27e78c4" value="Wählen Sie eine Stadt">
           <ul id="select-options-0388a2bc-2b5c-c534-8870-fc41b27e78c4" class="dropdown-content select-dropdown ">
              <li class=""><span>Wählen Sie eine Stadt</span></li>
              <li class="optgroup-option "><span>Berlin</span></li>
           </ul>
           <select name="timezone" id="timezone-0" class="initialized">
              <option value="No timezone">Wählen Sie eine Stadt</option>
              <optgroup label="Europe">
                 <option value="Europe/Berlin">Berlin</option>
              </optgroup>
           </select>
        </div>
     </div>
  </div>

我想选择柏林。

我尝试了 browser.find_by_css / text 等,但该元素不可见,我成为异常。

Traceback (most recent call last):
  File "matomo.py", line 598, in <module>
    browser.find_option_by_text('Berlin').first.click()
  File "/usr/lib/python3.6/site-packages/splinter/driver/webdriver/__init__.py", line 562, in click
    self._element.click()
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated
  (Session info: chrome=67.0.3396.99)
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.14.56-1-MANJARO x86_64)

有任何想法、解决方法或提示吗? :)

【问题讨论】:

标签: python selenium splinter


【解决方案1】:

您可以尝试使用显式等待来等待它,

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable(By.XPATH, "//span[contains(text(),'Berlin')]")).click()

Javascript函数的点击事件:

driver.execute_script("arguments[0].click()", ElementToClick)

【讨论】:

  • 这不起作用:/我尝试使用 Katalon Recorder (Selenium IDE for Chrome) 进行录制,但是当我播放录制的内容时,浏览器单击下拉列表,但无法选择该项目。跨度>
猜你喜欢
  • 2017-12-22
  • 1970-01-01
  • 1970-01-01
  • 2016-07-18
  • 2018-12-26
  • 2018-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多