From 7c6af440566b211e0afc80a6750f4bfe3091c3c2 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Thu, 4 Feb 2016 21:14:16 -0200 Subject: [PATCH] Fix selenium onClick link web step --- features/step_definitions/web_steps.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 84f25da..4073f87 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -43,14 +43,29 @@ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| click_link(link, :match => :prefer_exact) rescue Selenium::WebDriver::Error::UnknownError => selenium_error if selenium_error.message.start_with? 'Element is not clickable at point' - href = find_link(link)[:href] + link = find_link(link) + href = link[:href] + onclick = link[:onClick] warn "#{selenium_error.message}\n\n"\ - "Trying to overcome this by redirecting you to the link's href:\n"\ - "\t'#{href}'\n\n"\ - "Good luck and be careful that this may produce hidden links to work on tests!\n" + "Trying to overcome this by:\n" - visit href + onclick_return = true + + unless onclick.nil? + warn "\t* Running onClick JS:\n"\ + "\t\t'#{onclick}'\n" + onclick_return = page.execute_script onclick + end + + if onclick_return + warn "\t* Redirecting you to the link's href:\n"\ + "\t\t'#{href}'\n" + + visit href + end + + warn "\nGood luck and be careful that this may produce hidden links to work on tests!\n" else raise selenium_error end -- libgit2 0.21.2