我得到了你的问题,基本上你想检查一个网页可以打开多少个窗口。为了做到这一点,您可以使用下面的 xpath 来计算将在当前网页上打开的网页//a[@target="_blank"]您可以使用如下代码:import java.util.List;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.testng.annotations.Test;public class Testing { public static WebDriver driver; @Test public void test() throws InterruptedException { System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver"); driver = new ChromeDriver(); driver.get("https://stackoverflow.com"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS); Thread.sleep(1000); List<WebElement> elements = driver.findElements(By.xpath("//a[@target=\"_blank\"]")); int count =0; for ( WebElement element:elements) { count++; } System.out.println("Total number of window will be opened by this webpage is:"+ count); }}