1

I am trying to open a new tab and copy a new URL address to it

I currently am able to open a New tab by body.send_keys(Keys.CONTROL + 't')

    driver = webdriver.Firefox()
    #time.sleep(2)  #wait 1 second
    driver.get("https://stackoverflow.com/")
    body = driver.find_element_by_tag_name("body")
    body.send_keys(Keys.CONTROL + 't')

However I am not sure how to copy a new address to the URL

I tried

driver.find_element_by_link_text("").send_keys("https://google.com/")

But was not sure what to have inside link text

any suggestions?

Why not a duplicate:

Question is what goes inside the find_element_by_link_text(""). The page sent as duplicate only says urlLink. What does that mean ?

Mohamad Zein
  • 777
  • 1
  • 8
  • 33

2 Answers2

1

Mohamad.

This is how you can do it in java:

1) YOu go to Gmail homepage (baseURL)

   public void goToLoginPage() throws InterruptedException {
    driver.get(baseUrl + "/intl/en/mail/help/about.html");
    driver.findElement(By.id("gmail-sign-in")).click();
}

2) Here you open a new tab, by sending the selectLinkOpeninNewTab key combination (CTRL + T) to xpath("html") element. And then you simply navigate to another link (facebook in my case)

       public void openNewTab() throws InterruptedException {
   String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL+ "t");
    driver.findElement(By.xpath("html")).sendKeys(selectLinkOpeninNewTab);
    driver.navigate().to("https://facebook.com");

    Thread.sleep(2000);

}

I think it would be easy for you to convert it in Python

-2

The link How to open a new tab using Selenium WebDriver? that was posted as a comment to your question does indeed specify what goes into the link_text element. Look at the answers. Also, driver.get("someurl") should also work, just like how you navigated to a url when you launched the driver. I just tested it and it worked perfectly

Community
  • 1
  • 1
Ron D.
  • 110
  • 6