【问题标题】:Selenium Web Driver Ruby- Element not visible exceptionSelenium Web Driver Ruby- 元素不可见异常
【发布时间】:2013-10-29 12:28:02
【问题描述】:

网页sn-p是这样的:

<div id="HPSearchInput">
<form>
<ul></ul>
<input type="submit" data-ember-action="3" class="ch-btn searchBtn"        value="Search">
</form>

我正在使用以下 css 选择器来点击搜索按钮:

wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
wait.until { (driver.find_element(:css => "#HPSearchInput > form > input.ch-  btn.searchBtn")).click() }

它给了我错误:ElementNotVisibleError

我哪里错了?

【问题讨论】:

  • 向我们展示完整的错误堆栈..
  • [远程服务器] file:///C:/Users/x_x/AppData/Local/Temp/webdriver-profile2013102 8-7084-xaov0q/extensions/fxdriver@googlecode.com/components/command_processor .js :8225:in unknown': Element is not currently visible and so may not be interacte d with (Selenium::WebDriver::Error::ElementNotVisibleError) from [remote server] file:///C:/Users/x_x/AppData/Local/Temp/webdriver-p rofile20131028-7084-xaov0q/extensions/fxdriver@googlecode.com/components/command _processor.js:10816:in unknown' 来自 [远程服务器] file:///C:/Users/x_x/AppData/Local/Temp/webdriver-p ..........
  • 请在您的问题中添加任何额外信息,而不是在 cmets 中。

标签: ruby selenium selenium-webdriver


【解决方案1】:

它是一个不会立即出现的元素吗?如果是这样,请尝试:

wait.until { driver.find_element(:css => "#HPSearchInput > form > input.ch-  btn.searchBtn").displayed? }
driver.find_element(:css => "#HPSearchInput > form > input.ch-  btn.searchBtn").

【讨论】:

  • 谢谢它解决了这个问题。我已经接受它作为答案。另外,您能否告诉我为什么会显示 Elementnotvisible 错误,因为“元素”显然在页面上可见。
  • Selenium 使用几个标准来确定一个元素是否“可见”,主要是 Javascript 与 DOM 的交互。那里有一些比我在这里能提供的更彻底的答案。要理解的重要一点是,页面上大多数元素的加载都是异步,因此您不一定能准确预测它们何时可见。也就是说:JavaScript。
猜你喜欢
  • 2015-05-03
  • 1970-01-01
  • 1970-01-01
  • 2018-08-20
  • 1970-01-01
  • 2017-06-30
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
相关资源
最近更新 更多