【发布时间】:2015-08-31 21:07:33
【问题描述】:
我可以在同一浏览器中打开另一个标签页,但打开该页面后,在另一个标签页上我无法执行该操作。
当前情景举行:
- 提供凭据并登录帐户。
- 点击电子邮件地址或用户名通过它打开一个框架。
- 在该框架中单击“添加帐户”按钮。
- 点击“添加帐户”按钮后,我成功打开了另一个选项卡上的链接。
- 打开标签后,我可以打开那个窗口。
但打开该窗口后,我想在登录页面上再次提供凭据,但不想关闭帐户登录的第一个打开的选项卡。
我是在框架中做的,所以请检查下面的代码,并据此整合你的代码并帮助我。
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(10, TimeUnit.SECONDS);
if (operation.equalsIgnoreCase("Click")) {
temp.click();
}
if (operation.equalsIgnoreCase("newTab")) {
System.out.println("newTab" + temp);
Actions newTab = new Actions(driver);
newTab.keyDown(Keys.CONTROL).click(temp).keyUp(Keys.CONTROL).build().perform();
newTab.sendKeys(Keys.chord(Keys.CONTROL,Keys.TAB)).perform();
}
if (operation.equalsIgnoreCase("Verify")) {
System.out.println("Verify--->" + temp);
temp.isDisplayed();
}
testCaseStep = true;
} catch (Exception e) {
System.out.println("Exception occurred operateWebDriver"
+ e.getMessage());
//Taking snapshot when test case fail.
System.out.println("Taking snapshot");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("E:\\workspace for selenium\\AutomationFramework\\AutomationFramework\\Screenshots\\screenshot.jpg"));
}
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));
System.out.println("name temp ----->" + temp);
}
return temp;
}
}
【问题讨论】:
-
你想在哪里继续,是指在主窗口还是在新打开的窗口?
-
@SarithaG 我想在同一个窗口但在不同的选项卡上工作,比如在新选项卡上打开一个链接后,我的测试操作应该可以工作。
-
是的..使用那个链接。那会奏效的。
标签: java selenium selenium-webdriver