1. Selenium webdriver XPATH通过多个属性定位元素
直接调用方法GotoWebBrowserTab(wd,2)就可以切换到指定的tab。
方法:主要是通过and组合多个属性,例如:
wd.findElement(By.xpath("//em[
@testid='123'
and
@id='button_delete']")).click();
2. selenium webdriver 多个tab选项卡中测试(tab切换)
方法:通过getWindowHandles()方法,获得每个选项卡的WindowHandle,然后通过switchTo().window(WindowHandle)切换到指定的tab。本质上和切换frame一回事。
提供一个方法GotoWebBrowserTab:通过输入tab的顺序去切换到指定的tab。
public static voidGotoWebBrowserTab(WebDriver wd,
int iTabID)
throws InterruptedException
{
ArrayList tabs=
newArrayList();
for (String childTab :wd.getWindowHandles())
{
tabs.add(childTab);
}
if(iTabID>tabs.size())
{
Assert.fail(
"The expected tab numbershould < actual tab size ");
}
wd.switchTo().window((String) tabs.get(iTabID-1));
GL.wait(1);
}
备注:iTabID 为需要跳转到的tab次序,例如:切换到第2个tab,iTabID为2.
使用方法: