无法通过Selenium Java

时间:2017-11-17 19:24:34

标签: selenium-webdriver

我正在尝试使用selenium webDriver和Java自动化应用程序。和Chrome浏览器 我有以下情况: 在TestBase类中,我启动2个Chrome浏览器窗口,启动相同的WebDrivers实例2次(使用相同的WebDriver驱动程序;)并在每次启动后保存2个公共var中的WindowHandler:

public class TestBase {

    .......
    .......
    public static String WindowHandler_1 = null;
    public static String WindowHandler_2 = null;

        @BeforeSuite
    public static void setupTestBase() throws IOException, InterruptedException, SQLException {

        File f = new File("src");
        File fs = new File(f, "chromedriver.exe");      // chromedriver2_32
        System.setProperty("webdriver.chrome.driver", fs.getAbsolutePath());
    ....
    WindowHandler_1 = startBrowser(URL_1);          // A. driver.getWindowHandle(): =======> CDwindow-c725d6c5-247c-4df2-a5a8-419578569076
    WindowHandler_2 = startBrowser(URL_2);          // A. driver.getWindowHandle(): =======> CDwindow-f0bbdddf-e817-484d-b699-ff3907b99184
    }

        public static String startBrowser(String url) {

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--lang=de");
        options.addArguments("disable-infobars");
        driver = new ChromeDriver(options);


        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get(url);
        winTitle = driver.getTitle();
        String winHandler = driver.getWindowHandle();
        logger.info("A. driver.getWindowHandle(): =======> " + driver.getWindowHandle());
        return winHandler;
    }

在我真正的Test类中,名为Test1,我在Window 1中创建了一些Action,然后在完成后我想使用以下内容切换到Window 2:

public class Test1 extends TestBase {

......
......

    @BeforeClass
    public void setup() throws IOException, InterruptedException, SQLException {

        // Do some Action in window_1
        key.cleanKey(driver);               // handle ===========CDwindow-f0bbdddf-e817-484d-b699-ff3907b99184
        Thread.sleep(2000);

        // I have used the follwowing command after my action in window one is finsihed:
        // to switch to the new window (I want to switch to CDwindow-c725d6c5-247c-4df2-a5a8-419578569076 But it does not work with the following code)) 
        Set<String> handleswindow =driver.getWindowHandles();
        for(String windowHandle : handleswindow)
        {
            driver.switchTo().window(windowHandle);
        }

        for (int i = 0; i < MAX_ROW; i++) {
        // Do some action in window_2
            register.clean(driver, userEmail);
        }

我想切换到CDwindow-c725d6c5-247c-4df2-a5a8-419578569076但它不适用于以下代码,但我在日志“没有这样的窗口” 我也试过使用Window Titles但是没有工作

其他提示: 我在Window工具栏中看到2个Chrome Icon,其中Window_2的图标处于活动状态 请。看截图 enter image description here

感谢任何提示和支持

0 个答案:

没有答案