我有这段代码,它应该获取所有锚标记并单击它。由于链接在新选项卡中打开,因此存在getWindowHandle代码。运行代码后,我收到“ElementNotVisibleException”错误。我想知道我哪里出错了。
public void FetchingAllHomePageLinks() throws Exception
{
/* Anchor Tag(a) is a WebElement, hence its stored in the form of list */
List<WebElement> linkElements = driver.findElements(By.tagName("a"));
/* Array of string stores the linkelements size */
String[] linkTexts = new String[linkElements.size()];
int i=0;
//For every webelements consist of linkelements, its text has been stored in linktext
for(WebElement e : linkElements)
{
linkTexts[i]=e.getText();
i++;
}
for(String T : linkTexts)
{
if(!T.equals(null) || !T.equals("") || !T.isEmpty())
{
wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText(T))).click();
//Since the link if clicked opens in new tab hence getWindowHandles Code
String parentWindow = driver.getWindowHandle();
System.out.println("Parent Window ID is : " + parentWindow);
Set<String> allWindow = driver.getWindowHandles();
int count = allWindow.size();
System.out.println("Total Window : " + count);
for(String child:allWindow)
{
if(!parentWindow.equalsIgnoreCase(child))
{
driver.switchTo().window(child);
if(driver.getTitle().contains(errorTitle))
{
System.out.println("'" + T + "'" + " Is Under Construction");
}
else
{
System.out.println("'" + T + "'" + " Is working fine");
}
Thread.sleep(3000);
driver.close();
}
}
driver.switchTo().window(parentWindow);
}
}
driver.close();
}