1

I'm trying to save the link in variable gmail and trying to open it using send_keys. I'm confused if my declaration of the link is also wrong. It shows type str for declaration.

gmail= "https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin"
gmail.send_keys(keys.CONTROL+ Keys.RETURN)**

Type of gmail:

In [319]: type(gmail)
Out[319]: str

Please let me know if I can define a link and open it in a new tab in chrome browser driven by selenium.

Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52

2 Answers2

1

If you want to open an url in a new tab, you can do it this way:

gmail = 'http://example.com'
browser.execute_script('window.open("{}","_blank");'.format(gmail))
browser.switch_to.window(browser.window_handles[-1])

This code will open an url in a new tab. After all you have to close a new tab and go back to previous tab by using this code:

browser.close()
browser.switch_to.window(browser.window_handles[0])
0

Actually send_keys will just pass the value in the text field and it will not help you to open the link from it.So it you want to open a link using selenium.

driver.get("https://google.com")

Likewise you can pass the link so that page will gets open. if you want to do it in python then

import requests

requests.get("https://google.com")

  • Thanks Ganesh. But I think the question wasn't very clear. I am working in one window using selenium driver and wanted to open my gmail in next tab in same window using driver automatically. Hence I was trying to do what I was doing. If I do what you said, it will just open gmail in place of my currently opened website. I hope I have clarified question now. – Sumit Jiwane Sep 23 '17 at 09:10