ho preso approccio leggermente diverso, che era quello di costringere tutti i link per utilizzare target = _self in modo che potessero essere testati nella stessa finestra:
protected void testTextLink(WebDriver driver, final String linkText, final String targetPageTitle, final String targetPagePath) {
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement link = driver.findElement(By.linkText(linkText));
// ensure that link always opens in the current window
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('target', arguments[1]);", link, "_self");
link.click();
wait.until(ExpectedConditions.titleIs(targetPageTitle));
// check the target page has the expected title
assertEquals(driver.getTitle(), targetPageTitle);
// check the target page has path
assertTrue(driver.getCurrentUrl().contains(targetPagePath));
}
fonte
2013-03-04 13:43:05
non ho familiarità con selenio, quindi non posso eventualmente dare una risposta vera e propria. Tuttavia, come commento generale sul web design, raccomando contro l'attributo 'target', usando qualsiasi valore. La 'M' in HTML è 'Markup'; L'HTML non dovrebbe specificare il comportamento, solo il significato. Per un collegamento esterno, ti consiglio di utilizzare 'rel =" external "', quindi JavaScript per rendere tali collegamenti aperti in una nuova finestra. [Esempio] (http://articles.sitepoint.com/article/standards-compliant-world/3) –