gpt4 book ai didi

javascript - Rails/React 应用程序 - Capybara-Selenium::WebDriver::Error 在该点不可点击,其他元素将收到点击:

转载 作者:行者123 更新时间:2023-11-30 21:15:14 28 4
gpt4 key购买 nike

Gem 文件如下:

group :development, :test do
gem 'rspec-rails'
gem 'capybara-selenium'
gem "chromedriver-helper"
end

我正在使用 React View 测试 Rails 应用程序。测试正在进行中,但是当涉及到单击按钮时,它会单击其他地方。

rails_helper.rb

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)

# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'capybara/rspec'
require 'selenium/webdriver'
require 'chromedriver/helper'


Capybara.default_max_wait_time = 5


Capybara.javascript_driver = :selenium_chrome

RSpec.configure do |config|
config.raise_errors_for_deprecations!

end

测试规范.rb

require 'rails_helper'


feature "Select a Work Station" do
scenario "User should select a embedding work station" , js: true do

# 1- Go to login screen and authenticate
visit "http://localhost:3001"
fill_in('Email', :with => 'xxx')
fill_in('Password', :with => 'xxxx')
click_button("Submit")
# save_and_open_screenshot

# 2- Select an account
find('tr[accountname="Clinical Pathology Laboratories"]').click
# save_and_open_screenshot

# 3- Use default location
click_button("Save")
# save_and_open_screenshot

# 4- Click on the Embedding button
find('img[alt="Embedding"]').click

# 5- Start Session
find('#work_station_id').find('option', text: "Embedding #1").select_option

# ------------ clicking action ------
# page.driver.browser.action.move_to(find('button', text: "Start Session")).move_by(0, 5)
# expect(page).to have_select('#work_station_id')
# select 'Embedding #1', :from => '#work_station_id'
# page.driver.browser.mouse.move_to(find('button', text: "Start Session"), 0, 5)
# find('button[class="btn btn-success"]').click
# page.click_link_or_button('Start Session')
# click_button("Start Session")
end
end

问题开始于# ---------- 点击 Action ------ 和下面我尝试点击按钮的地方,但我希望它能让我前进到下一个页面。我尝试以多种不同的方式点击“开始 session ”按钮。相反,我得到那个按钮在点等处不可点击......

 Failure/Error: page.click_link_or_button('Start Session')

Selenium::WebDriver::Error::UnknownError:
unknown error: Element <button type="submit" class="btn btn-success" data-target="#undefined">...</button> is not clickable at point (628, 358). Other element would receive the click: <div class="wrapper wrapper-content animated fadeInRight">...</div>
(Session info: chrome=60.0.3112.101)
(Driver info: chromedriver=2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.12.6 x86_64)

最佳答案

您遇到的问题是您在尝试单击的按钮上有另一个元素 (

...
)。您需要弄清楚为什么它在那里,然后执行任何必要的操作以使该按钮可用。这可能包括滚动页面、增大屏幕尺寸以免重叠、关闭有问题的元素(如果它是模式等)。

此外,您正在使用 selenium 操作方法,但将 Capybara 元素传递给它们,而不是实际执行操作。

如果您想调用这些方法,您需要在 Capybara 元素上调用 native 以获取 selenium native 元素引用,并在操作链的末尾调用 perform 以实际执行某些操作。

page.driver.browser.action.move_to(find('button', text: "Start Session").native).move_by(0, 5).perform

关于javascript - Rails/React 应用程序 - Capybara-Selenium::WebDriver::Error 在该点不可点击,其他元素将收到点击:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45744483/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com