Asked  7 Months ago    Answers:  5   Viewed   53 times

How can I open a new tab in the existing Firefox browser using Selenium WebDriver (a.k.a. Selenium 2) in Java?

 Answers

27

The code below will open the link in a new tab.

String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);

The code below will open an empty new tab.

String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);
Tuesday, June 1, 2021
 
rblarsen
answered 7 Months ago
56

invisibilityOf()

invisibilityOf(WebElement element) is defined as:

public static ExpectedCondition<java.lang.Boolean> invisibilityOf(WebElement element)

An expectation for checking the element to be invisible

Here the expectation is that, the element must be present as well as visible as a pre-condition and the method will wait for the element to be invisible. At this point it is worth to mention that as the argument is of type WebElement, findElement(By by) have to successfully locate the element as a pre-condition. Hence NoSuchElementException can't be ignored.


invisibilityOfElementLocated()

invisibilityOfElementLocated(By locator) is defined as:

public static ExpectedCondition<java.lang.Boolean> invisibilityOfElementLocated(By locator)

An expectation for checking that an element is either invisible or not present on the DOM.

Here the expectation is clearly either the element is already invisible or not present in the HTML DOM. In this case the primary mission is the absence of the element which may occur even before the ExpectedCondition is invoked or during the timespan while the ExpectedCondition is active. So here we need to ignore NoSuchElementException as a mandatory measure.


Answering Question-2: Using wait.ignoring(org.openqa.selenium.NoSuchElementException.class); isn't justified as the pre-condition of invoking invisibilityOf(WebElement element) involves the fact that the element must be present in the DOM Tree as a mandatory measure.

Saturday, June 26, 2021
 
Amber
answered 6 Months ago
89

Wasim,

cdriver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");

You can use above line to open new tab in a same browser (Works in Firefox)

Friday, August 13, 2021
 
shin
answered 4 Months ago
81

Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable geckodriver that will run alongside the browser.

You need to download latest executable geckodriver from here and set this downloaded path from your machine as system property to run your test case with Firefox driver as below :

 System.setProperty("webdriver.gecko.driver","path/to downloaded/geckodriver.exe");
 DesiredCapabilities capabilities = DesiredCapabilities.firefox();
 capabilities.setCapability("marionette", true);
 WebDriver driver = new FirefoxDriver(capabilities);
  driver.get("http://stackoverflow.com");
Sunday, August 29, 2021
 
bimal
answered 4 Months ago
66

Usually chrome forces new window to run on the same Process ID. But, there are techniques which allows sites to open a new window without forcing it into the same process:

Use a link to a different web site that targets a new window without passing on referrer information.

<a href="http://differentsite.com" target="_blank" rel="noreferrer">Open in new tab and new process</a>

If you want the new tab to open in a new process while still passing on referrer information, you can use the following steps in JavaScript:

  • Open the new tab with about:blank as its target.
  • Set the newly opened tab's opener variable to null, so that it can't access the original page.
  • Redirect from about:blank to a different web site than the original page.

For example:

var w = window.open();
    w.opener = null;
    w.document.location = "http://differentsite.com/index.html";

Technically the original website still has access to the new one through w, but they treat .opener=null as a clue to neuter the window.

Source: https://bugzilla.mozilla.org/show_bug.cgi?id=666746

Monday, November 1, 2021
 
Conan
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share