【问题标题】:Element not found selenium web driver issue找不到元素硒网络驱动程序问题
【发布时间】:2023-03-15 12:01:01
【问题描述】:

我在 rspecspec 文件中使用 selenium:

wait.until { driver.find_element(:id => "data_source_type_name") }
RuleDesc = driver.find_element(:id, "data_source_type_name")
RuleDesc.send_keys "Mobility"

在 html 中我有:

<div class="col-sm-9">
        <input class="form-control" type="text" id="data_source_type_name" name="data_source_type[name]" required="">
      </div>

实际上在 Bootstrap 模式下(即仅在单击按钮后可见)我模拟了单击。它显示具有特定 div 的模式,但我收到以下错误:

[remote server] file:///tmp/webdriver-profile20150119-6088-50uggo/extensions/fxdriver@googlecode.com/components/command-processor.js:8991:in `fxdriver.preconditions.visible': Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)

编辑:当我打印 puts RuleDesc.displayed?它返回 false,但在 webdriver 中它正在显示。

【问题讨论】:

  • 你能试试这个吗,find(:xpath, "//*[contains(@id, 'data_source_type_name')]")
  • 我尝试的每个选择器都返回相同的结果,除了 driver.execute_script("document.getElementById('data_source_type_name').value ='Test value';") 确实有效,但我不想使用 javascript跨度>

标签: ruby-on-rails ruby selenium rspec


【解决方案1】:

我做了一些自定义,在规范中我将包含 Bootstrap 模态的 css 更改为 display:block;在访问该容器中的元素之前使用javascript(不是通过单击按钮触发的,为什么?不知道,但它正在显示。)。 Tada,然后每个选择器 css、Xpath 或 ID 都像奶油一样光滑。

【讨论】:

    猜你喜欢
    • 2015-12-27
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 2018-08-27
    相关资源
    最近更新 更多