测试场景:
目前,我可以打开另一个标签,但这些标签无法获取Gmail网址。此外,我正在使用关键字驱动框架。
那么,任何人都可以帮我解决它吗?
方法中的条件:
if(operation.equalsIgnoreCase("urlOnNewTab")){
temp.sendKeys(Keys.CONTROL+"t");
ArrayList<String> tab = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tab.get(1));
/*String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
temp.sendKeys(selectLinkOpeninNewTab);*/
driver.get(value);
if (operation.equalsIgnoreCase("SendKey")) {
temp.sendKeys(value);
}
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
if (operation.equalsIgnoreCase("Click")) {
temp.click();
}
if (operation.equalsIgnoreCase("Verify")) {
System.out.println("Verify--->" + temp);
temp.isDisplayed();
}
}
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));
}else if (locator.equalsIgnoreCase("linkText")) {
temp = driver.findElement(By.linkText(objectName));
}else if (locator.equalsIgnoreCase("cssSelector")) {
temp = driver.findElement(By.cssSelector(objectName));
}
return temp;
答案 0 :(得分:0)
我没有得到任何人的反馈,但我尝试了下面的代码,根据我的问题它对我有用。
<强>代码:强>
if(operation.equalsIgnoreCase("urlOnNewTab")){
temp.sendKeys(Keys.CONTROL+"t");
driver.get(value);
if (operation.equalsIgnoreCase("SendKey")) {
temp.sendKeys(value);
}
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
if (operation.equalsIgnoreCase("Click")) {
temp.click();
}
if (operation.equalsIgnoreCase("Verify")) {
System.out.println("Verify--->" + temp);
temp.isDisplayed();
}
}
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));
}else if (locator.equalsIgnoreCase("cssSelector")) {
temp = driver.findElement(By.cssSelector(objectName));
}
return temp;