1

I have a button that opens a link in a same window, but I need to open it in a separate tab by doing some scripting. I am working in Ruby and here is my code:

Given /^User clicks on the New User Link$/ do
    page.driver.browser.switch_to.window (page.driver.browser.window_handles.last)
    find(:xpath, "//*[@id='slideshow']/div[1]/div/a/img, ").click
end

This code won't work for me. Please let me know if you see anything wrong in this code.

Kai
  • 38,985
  • 14
  • 88
  • 103

1 Answers1

0

bgoad gave an answer for your question there. Here it is:

def open_new_window(url)
  a = @driver.execute_script("var d=document,a=d.createElement('a');a.target='_blank';a.href=arguments[0];a.innerHTML='.';d.body.appendChild(a);return a", url)
  a.click
  @driver.switch_to.window(@driver.window_handles.last)
end

Note: I haven't tried it

Community
  • 1
  • 1
Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123