0
votes

I practiced with function switchToWindow on codeception. But it doesn't work with me

Anybody can help me resolve my issue. I want to switch to login popup for inputting email/password but i can't. ![enter image description here][1] Here is my scenario On current page (page A) click login button => new window is opened for user inputting email/password of facebook. After click submit button, it will redirect to last window (page A)

Here is my code 

$I = new AcceptanceTester($scenario);
$I->amOnPage('/leaderboard'); 
$I->click('#fb-login');
$I->executeInSelenium(function (\Webdriver\Session $webdriver) {
    $handles=$webdriver->window_handles();
    $last_window = end($handles);
    $webdriver->focusWindow($last_window);
});
$I->fillField('#email','[email protected]');
$I->fillField('#pass','aaa');
$I->click('//*[@id="u_0_1"]');

Thanks

2

2 Answers

0
votes

Use the following code:

$I->executeInSelenium(function (Webdriver $webdriver) {
   $handles=$webdriver->getWindowHandles();
   $last_window = end($handles);
   $webdriver->switchTo()->window($last_window);
});

And then

$I->switchToWindow();

to come back to main window if needed

0
votes

Try this one,

$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
             $handles=$webdriver->getWindowHandles(); 
             $first_window = ($handles[0]);      
             $last_window = ($handles[1]);
             $webdriver->switchTo()->window($last_window);      
        });