如何切换到未定义标题的窗口

时间:2017-11-20 06:18:18

标签: java selenium

Title is not defined in the window, so getTitle() makes no sense

// Getting current/ Parent window handle
String currentWindoHadle= driver.getWindowHandle();

// Switch to PrintStandardInv window
CustomSeleniumMethods.switchToWindowByTitle(driver, "", tests);

public static void switchToWindowByTitle(WebDriver driver, String windowTitle, ExtentTest tests) throws IOException

{
try {
boolean isWindowFound=false;
String currentWindoHadle1= driver.getWindowHandle();
Set<String> allWindowHandles1= driver.getWindowHandles();
for(String h:allWindowHandles1)
{
if(!h.equals(currentWindoHadle1))
driver.switchTo().window(h);
String title= driver.getTitle();
        System.out.println("title inside function call " + title);
        if(title.equals(windowTitle))
        {
            tests.pass("Switched to window title: "+windowTitle);
            driver.manage().window().maximize();
            isWindowFound=true;
            break;              
        }

这是有效的,但是任何人都可以建议更好的方法切换到未定义标题的窗口。请参考emage。这里使用getTitle()与“”空白窗口标题

进行比较没有意义

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,如

'use strict';
var app = angular.module('starApp');

/* Application controller (for top-level auth) */
app.controller('SearchController', ['$location', 'AuthenticationService',
'$scope', '$http',
function($location, AuthenticationService, $scope, $http) {

    console.log('*** SearchController ***');

    $scope.items = [];

    (function getData() {
        var apiURL = "https://swapi.co/api/planets";
        axios.get(apiURL).then(function(response) {
            showDetail(response.data);
        });
    })();

    function showDetail(data) {
        $scope.items = data.results;
    }

}]);

我们只获取当前网址,如果我的目标网址以某个内容开头或包含某些内容,那么我们可以像这样编写代码