I want to open a URL on new tab by clicking on button for add account. I am working with framework, also I've found some solution but don't understand how to apply it.
Below are the code where I've find the element and return it for performing the operations. Can any one let me know with integrate the code for opening the url in new tab, using this code?
private boolean operateWebDriver(String operation, String Locator,
String value, String objectName) throws Exception {
boolean testCaseStep = false;
try {
System.out.println("Operation execution in progress");
WebElement temp = getElement(Locator, objectName);
if (operation.equalsIgnoreCase("SendKey")) {
temp.sendKeys(value);
}
Thread.sleep(1000);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
if (operation.equalsIgnoreCase("Click")) {
temp.click();
//try to open account on another tab.
String myWindowHandel= driver.getWindowHandle();
driver.switchTo().window(myWindowHandel);
}
if (operation.equalsIgnoreCase("Verify")) {
System.out.println("Verify--->" + temp);
temp.isDisplayed();
}
testCaseStep = true;
} catch (Exception e) {
System.out.println("Exception occurred operateWebDriver"
+ e.getMessage());
// Take screenshot if any testcase is not working.
System.out.println("Taking Screen Shot");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:\\softs\\eclipse-jee-kepler-SR1-win32\\Workspace\\AutomationFramework\\Screenshot\\screenshot.jpeg"));
}
return testCaseStep;
}
public WebElement getElement(String locator, String objectName)
throws Exception {
WebElement temp = null;
System.out.println("Locator-->" + locator);
if (locator.equalsIgnoreCase("id")) {
temp = driver.findElement(By.id(objectName));
} else if (locator.equalsIgnoreCase("xpath")) {
temp = driver.findElement(By.xpath(objectName));
System.out.println("xpath temp ----->" + temp);
} else if (locator.equalsIgnoreCase("name")) {
temp = driver.findElement(By.name(objectName));
}
return temp;
}
}