0

我正在尝试使用 selenium webdriver 使用 phantom 自动化 Dapp 我正在使用多窗口处理程序,但不幸的是,我的代码只给了我一个窗口,它没有将 Phantom 钱包视为单独的选项卡或窗口。我想点击连接按钮,但我无法连接,即使它没有将此弹出窗口视为单独的窗口或选项卡

@Test

    public void Phantom() 
    {
        ChromeOptions opt = new ChromeOptions();
        opt.addExtensions(new File("phantom.crx"));
        System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
        WebDriver driver = new ChromeDriver(opt);
        driver.get("url");
        String parent=driver.getWindowHandle();
         
        // This will return the number of windows opened by Webdriver and will return Set of St//rings
         Set <String>s1=driver.getWindowHandles();
         
        // Now we will iterate using Iterator
        Iterator<String> I1= s1.iterator();
         
        while(I1.hasNext())
        {
         
           String child_window=I1.next();
         
        // Here we will compare if parent window is not equal to child window then we            will close
         
        if(!parent.equals(child_window))
        {
        driver.switchTo().window(child_window);
        driver.findElement(By.xpath("//*[@id=\"root\"]/main/div/div/section/button[2]")).click();
         driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
        driver.findElement(By.xpath("//*[@id=\"root\"]/main/div[2]/div/form/div[1]/div/section/div/textarea")).sendKeys("phrase");
        driver.findElement(By.xpath("//*[@id='root']/main/div[2]/div/form/div[2]/button")).click();  
         driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
        driver.findElement(By.xpath("//*[@id=\"root\"]/main/div[2]/div/div/button")).click(); 
        driver.findElement(By.xpath("//*[@id='root']/main/div[2]/div/form/div[1]/div/section/input")).sendKeys("password");
        driver.findElement(By.xpath("//*[@id='root']/main/div[2]/div/form/div[1]/div/section/div[1]/input")).sendKeys("password");
        driver.findElement(By.xpath("//*[@id=\"root\"]/main/div[2]/div/form/div[1]/div/section/div[2]/span/input")).click(); 
        driver.findElement(By.xpath("//*[@id=\"root\"]/main/div[2]/div/form/div[2]/button")).click(); 
        driver.findElement(By.xpath("//*[@id=\"root\"]/main/div[2]/div/div[2]/button")).click(); 
        driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS) ;
        driver.findElement(By.xpath("/html/body/div/main/div[2]/div/div[2]/button")).click(); 
        driver.close();
        // once all pop up closed now switch to parent window
        driver.switchTo().window(parent);
        //close the parent window
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
        driver.findElement(By.xpath("//*[@id=\"manu-box\"]/div[1]/div/div/div/div[2]/div[2]/button")).click(); 
        driver.findElement(By.xpath("//*[@id=\"uncontrolled-tab-example-tabpane-sol\"]/div/div[3]/div/div[1]/div")).click(); 
//  //at this point there is no focused window, we have to explicitly switch back to some window.
        
    

    }
        

        }
        String wallet1= driver.getWindowHandle();
        Set <String> all=driver.getWindowHandles();
        
        System.out.println("No. of windows" + all.size());
            
        
}
}

在此处输入图像描述

4

0 回答 0