能够切换驱动程序但不能切换焦点

能够切换驱动程序但不能切换焦点

本文介绍了能够切换驱动程序但不能切换焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:假设我有两个标签TAB1和TAB2.我想根据某些条件在这些选项卡之间切换.使用下面的代码,我可以在选项卡之间切换驱动程序,但是选项卡的焦点不会改变.

Scenario: Lets say I have two tabs TAB1 and TAB2. I want to switch between these tabs based on certain criteria. With the below code I'm able to switch the driver between the tabs but tab focus is not getting changed.

请帮助我.是否有可能实现这一目标?

Help me on this..Is there any possibility to achieve this?

public static Boolean SwitchWindow(string title)
{
    try
    {
        var currentWindow_title = Driver.Title;
        var currenhandle = Driver.CurrentWindowHandle;
        var availableWindows = new List<string>Driver.WindowHandles);

        if (currentWindow_title != title)
        {
            foreach (string w in availableWindows)
            {
                if (currenhandle != w)
                {
                    Driver.SwitchTo().Window(w);

                    var tit = Driver.Title;

                    if (Driver.Title == title)
                    {
                        break;
                    }
                }
            }
        }
    }
}

推荐答案

如果我没记错的话,您想打开子窗口.试试这个,希望对您有帮助

If i am not wrong, you want to switch on child window.Try this, hope this will help for you

    //storing parent window reference into string variable
String ParentWindow = driver.getWindowHandle();

//switching from parent to pop up window
for (String Child_Window : driver.getWindowHandles())
{
driver.switchTo().window(Child_Window);

//implicit wait for visibility of pop up button
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//explicit wait for visibility of pop up button
WebDriverWait wait = new WebDriverWait(driver, 30);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("??")));
driver.findElement(By.xpath("//input[@value='??']")).click();
}
//Switching back to Parent Window
driver.switchTo().window(ParentWindow);
driver.switchTo().defaultContent();

这篇关于能够切换驱动程序但不能切换焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 11:55