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.

2

2 Answers 2

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])
Sign up to request clarification or add additional context in comments.

Comments

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")

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.