水豚 default_max_wait_time 没有应用新的时间
Capybara default_max_wait_time doesnt apply new timing
我正在用 Capybara 和 Ruby 编写脚本,我正在尝试将 default_max_wait_time 从 2 秒更改为 200 秒。我通读了文档,但当我将文件上传到 be 站点时,它似乎仍然对我不起作用。你能告诉我做错了什么吗?
require 'kimurai'
require 'pry'
require 'capybara/config'
# $app_path = 'path_to_the_file'
class Uploader < Kimurai::Base
@name = "new_google_play_console_app"
@engine = :selenium_chrome
@start_urls = ["link_to_the_web_page"]
def parse(response, url:, data: {})
Capybara.configure do |config|
config.default_max_wait_time = 200
puts config.default_max_wait_time
end
browser.click_button('I’m sure, opt out', wait: 100)
browser.attach_file($app_path) do
browser.click_button('Browse files')
end
sleep 200
browser.click_on('Save')
问题是脚本没有等待文件上传并尝试点击 'Save'。不仅在这里 - 有时,当我单击按钮时,网站会加载结果。但是我的脚本不会等待它并继续执行。所以,这就是为什么我现在放 ```sleep`` 的原因。但是我想避免它
上传过程完成后出现table:
Thomas,这里有一个代码和一个错误。上传完成后,我需要点击``保存```按钮,在您完成上传之前该按钮不会激活。
代码
app_releases = browser.find_link(title: 'App releases')
app_releases.click
manage_btn = browser.all(:button, text: 'Manage')
manage_btn[0].click
sleep 1
create_release_btn = browser.all(:button, text: 'Create release')
create_release_btn[1].click
browser.click_button('Opt out', wait: 100)
browser.click_button('I’m sure, opt out', wait: 100)
browser.attach_file($app_path) do
browser.click_button('Browse files')
browser.assert_text('App download size', wait: 200)
end
# browser.assert_text('App download size', wait: 200) - tried to put it inside the upload process and outside. Didn't work.
# sleep 200
browser.click_on('Save')
错误:
WARN: Unresolved specs during Gem::Specification.reset:
selenium-webdriver (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
I, [2020-06-10 19:10:54 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Spider: started: new_google_play_console_app
D, [2020-06-10 19:10:56 +0300#37958] [M: 70296153575020] DEBUG -- new_google_play_console_app: BrowserBuilder (selenium_chrome): created browser instance
I, [2020-06-10 19:10:56 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: started get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppDashboardPlace:p=net.cityhive.store.martinbrothers&appid=4975449495408659761
2020-06-10 19:10:56 WARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: finished get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppDashboardPlace:p=net.cityhive.store.martinbrothers&appid=4975449495408659761
I, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Info: visits: requests: 1, responses: 1
D, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] DEBUG -- new_google_play_console_app: Browser: driver.current_memory: 501740
I, [2020-06-10 19:11:37 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: driver selenium_chrome has been destroyed
I, [2020-06-10 19:11:37 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Spider: stopped: {:spider_name=>"new_google_play_console_app", :status=>:completed, :error=>nil, :environment=>"development", :start_time=>2020-06-10 19:10:54 +0300, :stop_time=>2020-06-10 19:11:37 +0300, :running_time=>"42s", :visits=>{:requests=>1, :responses=>1}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
MacBook-Air-Nikita:spiders nikita$ ruby new_google_play_console_app.rb Liquor\ Super\ Store liquorsuper
WARN: Unresolved specs during Gem::Specification.reset:
selenium-webdriver (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
I, [2020-06-11 13:37:28 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Spider: started: new_google_play_console_app
D, [2020-06-11 13:37:29 +0300#38739] [M: 70329536056940] DEBUG -- new_google_play_console_app: BrowserBuilder (selenium_chrome): created browser instance
I, [2020-06-11 13:37:29 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: started get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppListPlace
2020-06-11 13:37:29 WARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: finished get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppListPlace
I, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Info: visits: requests: 1, responses: 1
D, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] DEBUG -- new_google_play_console_app: Browser: driver.current_memory: 500852
I, [2020-06-11 13:38:10 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: driver selenium_chrome has been destroyed
F, [2020-06-11 13:38:10 +0300#38739] [M: 70329536056940] FATAL -- new_google_play_console_app: Spider: stopped: {:spider_name=>"new_google_play_console_app", :status=>:failed, :error=>"#<Capybara::ElementNotFound: Unable to find link or button \"Save\">", :environment=>"development", :start_time=>2020-06-11 13:37:28 +0300, :stop_time=>2020-06-11 13:38:10 +0300, :running_time=>"42s", :visits=>{:requests=>1, :responses=>1}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
Traceback (most recent call last):
13: from new_google_play_console_app.rb:196:in `<main>'
12: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:124:in `crawl!'
11: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:124:in `each'
10: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:128:in `block in crawl!'
9: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:204:in `request_to'
8: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:204:in `public_send'
7: from new_google_play_console_app.rb:187:in `parse'
6: from new_google_play_console_app.rb:55:in `appReleases'
5: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
4: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/actions.rb:26:in `click_link_or_button'
3: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:52:in `find'
2: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:291:in `synced_resolve'
1: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/base.rb:83:in `synchronize'
/usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:302:in `block in synced_resolve': Unable to find link or button "Save" (Capybara::ElementNotFound)
Capybara.default_max_wait_time
是 Capybara 等待匹配元素出现在页面上或从页面上消失的时间量。在您的情况下,这意味着在您的脚本中您需要确定页面上的哪些更改表明文件已完成上传并等待
browser.attach_file($app_path) do
browser.click_button('Browse files')
end
# Have this look for whatever indicates the file upload has completed
browser.assert_text('Your file has uploaded', wait: 200)
browser.click_on('Save')
用 browser.has_button?('Save', wait: 200)
解决了。上传成功后会出现保存按钮
我正在用 Capybara 和 Ruby 编写脚本,我正在尝试将 default_max_wait_time 从 2 秒更改为 200 秒。我通读了文档,但当我将文件上传到 be 站点时,它似乎仍然对我不起作用。你能告诉我做错了什么吗?
require 'kimurai'
require 'pry'
require 'capybara/config'
# $app_path = 'path_to_the_file'
class Uploader < Kimurai::Base
@name = "new_google_play_console_app"
@engine = :selenium_chrome
@start_urls = ["link_to_the_web_page"]
def parse(response, url:, data: {})
Capybara.configure do |config|
config.default_max_wait_time = 200
puts config.default_max_wait_time
end
browser.click_button('I’m sure, opt out', wait: 100)
browser.attach_file($app_path) do
browser.click_button('Browse files')
end
sleep 200
browser.click_on('Save')
问题是脚本没有等待文件上传并尝试点击 'Save'。不仅在这里 - 有时,当我单击按钮时,网站会加载结果。但是我的脚本不会等待它并继续执行。所以,这就是为什么我现在放 ```sleep`` 的原因。但是我想避免它
上传过程完成后出现table:
Thomas,这里有一个代码和一个错误。上传完成后,我需要点击``保存```按钮,在您完成上传之前该按钮不会激活。
代码
app_releases = browser.find_link(title: 'App releases')
app_releases.click
manage_btn = browser.all(:button, text: 'Manage')
manage_btn[0].click
sleep 1
create_release_btn = browser.all(:button, text: 'Create release')
create_release_btn[1].click
browser.click_button('Opt out', wait: 100)
browser.click_button('I’m sure, opt out', wait: 100)
browser.attach_file($app_path) do
browser.click_button('Browse files')
browser.assert_text('App download size', wait: 200)
end
# browser.assert_text('App download size', wait: 200) - tried to put it inside the upload process and outside. Didn't work.
# sleep 200
browser.click_on('Save')
错误:
WARN: Unresolved specs during Gem::Specification.reset:
selenium-webdriver (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
I, [2020-06-10 19:10:54 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Spider: started: new_google_play_console_app
D, [2020-06-10 19:10:56 +0300#37958] [M: 70296153575020] DEBUG -- new_google_play_console_app: BrowserBuilder (selenium_chrome): created browser instance
I, [2020-06-10 19:10:56 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: started get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppDashboardPlace:p=net.cityhive.store.martinbrothers&appid=4975449495408659761
2020-06-10 19:10:56 WARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: finished get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppDashboardPlace:p=net.cityhive.store.martinbrothers&appid=4975449495408659761
I, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Info: visits: requests: 1, responses: 1
D, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] DEBUG -- new_google_play_console_app: Browser: driver.current_memory: 501740
I, [2020-06-10 19:11:37 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: driver selenium_chrome has been destroyed
I, [2020-06-10 19:11:37 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Spider: stopped: {:spider_name=>"new_google_play_console_app", :status=>:completed, :error=>nil, :environment=>"development", :start_time=>2020-06-10 19:10:54 +0300, :stop_time=>2020-06-10 19:11:37 +0300, :running_time=>"42s", :visits=>{:requests=>1, :responses=>1}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
MacBook-Air-Nikita:spiders nikita$ ruby new_google_play_console_app.rb Liquor\ Super\ Store liquorsuper
WARN: Unresolved specs during Gem::Specification.reset:
selenium-webdriver (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
I, [2020-06-11 13:37:28 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Spider: started: new_google_play_console_app
D, [2020-06-11 13:37:29 +0300#38739] [M: 70329536056940] DEBUG -- new_google_play_console_app: BrowserBuilder (selenium_chrome): created browser instance
I, [2020-06-11 13:37:29 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: started get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppListPlace
2020-06-11 13:37:29 WARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: finished get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppListPlace
I, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Info: visits: requests: 1, responses: 1
D, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] DEBUG -- new_google_play_console_app: Browser: driver.current_memory: 500852
I, [2020-06-11 13:38:10 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: driver selenium_chrome has been destroyed
F, [2020-06-11 13:38:10 +0300#38739] [M: 70329536056940] FATAL -- new_google_play_console_app: Spider: stopped: {:spider_name=>"new_google_play_console_app", :status=>:failed, :error=>"#<Capybara::ElementNotFound: Unable to find link or button \"Save\">", :environment=>"development", :start_time=>2020-06-11 13:37:28 +0300, :stop_time=>2020-06-11 13:38:10 +0300, :running_time=>"42s", :visits=>{:requests=>1, :responses=>1}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
Traceback (most recent call last):
13: from new_google_play_console_app.rb:196:in `<main>'
12: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:124:in `crawl!'
11: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:124:in `each'
10: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:128:in `block in crawl!'
9: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:204:in `request_to'
8: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:204:in `public_send'
7: from new_google_play_console_app.rb:187:in `parse'
6: from new_google_play_console_app.rb:55:in `appReleases'
5: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
4: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/actions.rb:26:in `click_link_or_button'
3: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:52:in `find'
2: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:291:in `synced_resolve'
1: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/base.rb:83:in `synchronize'
/usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:302:in `block in synced_resolve': Unable to find link or button "Save" (Capybara::ElementNotFound)
Capybara.default_max_wait_time
是 Capybara 等待匹配元素出现在页面上或从页面上消失的时间量。在您的情况下,这意味着在您的脚本中您需要确定页面上的哪些更改表明文件已完成上传并等待
browser.attach_file($app_path) do
browser.click_button('Browse files')
end
# Have this look for whatever indicates the file upload has completed
browser.assert_text('Your file has uploaded', wait: 200)
browser.click_on('Save')
用 browser.has_button?('Save', wait: 200)
解决了。上传成功后会出现保存按钮