【问题标题】:send_keys is not working in phantomjs, but its working fine on firefoxsend_keys 在 phantomjs 中不工作,但在 firefox 上工作正常
【发布时间】:2014-10-06 08:39:19
【问题描述】:

我无法与文本字段text_field(:css => '.search-query').send_keys(:enter) 进行交互 ,它在 firefox 和 chrome 上工作正常,但在 Phantomjs 中不工作

<div class="search search-session">
  <form class="search-form search-form-session" action="#">
    <i class="icon-search"></i>
    <input type="text" class="input-medium search-query-session search-query" placeholder="Search">
  </form>

我认为 send_keys 在 phatomjs 中不起作用,谁能帮我解决这个问题

这是错误信息

:Selenium::WebDriver::Error::InvalidElementStateError: {"errorMessage":"元素当前不可交互,可能无法操作","re​​quest":{"headers":{"Accept":"application/ json","接受-

【问题讨论】:

  • 错误是什么?您确定该元素存在于 PhantomJS 中吗? PhantomJS 最初的视口尺寸很小,网站可能会根据用户代理更改内容。
  • 这是错误消息:Selenium::WebDriver::Error::InvalidElementStateError: {"errorMessage":"元素当前不可交互,可能无法操作","re​​quest":{"headers ":{"Accept":"application/json","Accept-

标签: phantomjs watir-webdriver


【解决方案1】:

我遇到了同样的问题, 解决方案是在启动 Web 驱动程序时强制用户代理(使用 DesiredCapabilities) 使用类似的东西应该可以解决问题:

require 'watir-webdriver'

capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
browser = ::Watir::Browser.new driver

来源:https://gist.github.com/tehprofessor/5497198

【讨论】:

  • 我试过了,但没有用,在 phantomjs 中使用 chrome / firefox 的用户代理发送键仍然出错
  • 请给我建议可能的方法
  • 尝试截屏以确保该字段可编辑,如下所述:watirwebdriver.com/screenshots
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多