1

I am new to Ruby language. i want to work with chrome browser using selenium web driver. i am trying to open new tab in chrome browser. but i am unable to get.could you please check below code once.suggest me if anything wrong

require 'selenium-webdriver'
$driver = Selenium::WebDriver.for :chrome
$driver.navigate.to "http://www.google.com/"
$driver.manage.timeouts.implicit_wait = 30

body = $driver.find_element(:tag_name,'body')
body .send_keys(:control,'t')
$driver.navigate.to "http://www.ask.com/"

output: New tab in chrome is not opened,second url also opened in the same page which is already opened with first url.

santoshi
  • 65
  • 1
  • 9

1 Answers1

0

You should use get method to open URL and also I have corrected your find_element method , Please try below updated code :

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :chrome
driver.get('http://google.com/')
driver.manage.timeouts.implicit_wait = 30

body = driver.find_element(:tag_name => 'body')
body.send_keys(:control, 't')
driver.get('http://www.ask.com/')

Hope above will solve your issue.

Helping Hands
  • 5,292
  • 9
  • 60
  • 127
  • i have done as u suggested, still i am not getting as "new tab is not opened". The above code is working fine in firefox browser but it wont work in chrome,.please help me.... – santoshi Jan 29 '15 at 13:58
  • Can you please update your chrome browser? May be version issue. – Helping Hands Jan 30 '15 at 03:33
  • i am using chrome latest version 40, which version of chrome browser will support selenium 2.44 , please suggest me – santoshi Jan 30 '15 at 09:05
  • Can you tell me where you have put your "chromedriver.exe" ?? – Helping Hands Jan 30 '15 at 09:10
  • path of chromedriver.exe is "C:\Ruby\bin", and this path is set in environment variables – santoshi Jan 30 '15 at 09:12
  • please add path like C:\Ruby\bin\chromedriver.exe separate by semicolon with that C:\Ruby\bin . Then restart pc and run your program again. – Helping Hands Jan 30 '15 at 09:14
  • I have done as u suggested even now also i am getting same i.e New tab in chrome is not opened,second url also opened in the same page which is already opened with first url. please help me.... – santoshi Jan 30 '15 at 11:33