红宝石点上的元素不可点击

时间:2015-07-06 21:43:49

标签: jquery ruby selenium webdriver element

我正在使用Rspec,Selenium Webdriver,Ruby,Mac OSx当我为Firefox执行脚本时,一切顺利。当我更改为Chrome版本43.0.2357.130时,出现错误

class RedirectAuthenticatedUserMixin(object):
    def dispatch(self, request, *args, **kwargs):
        self.request = request
        if request.user.is_authenticated():
            redirect_to = self.get_authenticated_redirect_url()
            response = HttpResponseRedirect(redirect_to)
            return _ajax_response(request, response)
...

我试图添加等待时间,也有研究,我发现Java有可能与JavascriptExecutor有关。

可以用Ruby做点什么吗?

>      unknown error: Element is not clickable at point (385, 575). Other element would receive the click: <div class="ajax-progress
> ajax-progress-throbber">...</div>
>        (Session info: chrome=43.0.2357.130)
>        (Driver info: chromedriver=2.15.322455 (ae8db840dac8d0c453355d3d922c91adfb61df8f),platform=Mac OS X 10.10.4
> x86_64) (Selenium::WebDriver::Error::UnknownError)

build_page.choose_account_button.click

失败

但是,前一行返回坐标。

更新

我解决了这个问题

http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html

And(/^User select account and telephone to upgrade$/) do
  @profile = get_account("consumer.postpaid.user9")
  RubyHelper.wait_js_load_in_seconds(5)
  accounts = @driver.find_elements(:css => "p.account-number")
  accounts.each do |account|
    account.click if account.text.include? @profile.ban
    account
   # scroll the element into view, then return its location
   # build_page.choose_account_button.location_once_scrolled_into_view
    build_page.choose_account_button.click
  end
  RubyHelper.wait_js_load_in_seconds(6)
  elements = @driver.find_elements(:css => "h3.phone-number")
  elements.each do |element|
    element.click if element.text == @profile.phone
    element
  end

1 个答案:

答案 0 :(得分:0)

看起来你在那里进行了一些ajax调用,阻止了点击该元素。虽然添加等待最初会解决您的问题,但请考虑在点击方法中添加 wait_for_ajax 方法。

例如:

def wait_for_ajax(timeout = 30)
  wait = Selenium::WebDriver::Wait.new timeout: timeout
  wait.until { @driver.execute_script("return jQuery.active == 0") == true }
end

这样做的好处是你不会在等待 bad 的等待中进行硬编码。