Selenide: [Question] How can selenide switch to the new window or new tab in browser?

Created on 9 May 2016  路  13Comments  路  Source: selenide/selenide

As title, if a new window appear after click a web element ? How can I switch to the new window or new tab in browser?

question

Most helpful comment

You can do it multiple ways:

import static com.codeborne.selenide.Selenide.*;

// by index
switchTo().window(1);

// by name or title or handle
switchTo().window("Title of the window");

// for switching to default window
switchTo().defaultContent();

All 13 comments

You can do it multiple ways:

import static com.codeborne.selenide.Selenide.*;

// by index
switchTo().window(1);

// by name or title or handle
switchTo().window("Title of the window");

// for switching to default window
switchTo().defaultContent();

@anilreddy Thank for the answer!
@yisake exactly, use switchTo() method.

@anilreddy Many thanks.
@asolntsev I think many people like me are new to selenide need more example with many detail for selenide. ~~

@yisake Absolutely agree! Good point!
Don't you want to help us?
Source of selenide.org is also in github.com/codeborne/selenide, but in branch "gh-pages".
Feel free to send pull requests there!

@yisake @anilreddy
just wanted to say that when I started to use Selenide i had the same problem. When I found out that there are lots of examples at https://github.com/codeborne/selenide/tree/master/src/test/java/integration testing, everything became much easier. Please look at those examples if you are not doing it already

@thasherwin Good point, thank you!

Hi, Andrei (@asolntsev)!
I have just start to use this very helpful library and really love it, Thank you very much for sharing it.
I have seen your videos in youtube about using the library and read most of main pages at project website too. I read and try to use eclipse IDE "code proposals" to start creating tests and realise that to use them they ALL should to be to imported to the test (java) file. It may look funny but being a newbie I should to ask a question. Is there a selenide libraries FULL list to be imported in the tests or there is another better way to get code (suggestions) proposals?
List should look like this:

import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.appear;
import static com.codeborne.selenide.Condition.appears;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Condition.attribute;
import static com.codeborne.selenide.Condition.cssClass;
import static com.codeborne.selenide.Condition.hidden;
import static com.codeborne.selenide.Condition.disappear;
import static com.codeborne.selenide.Condition.disappears;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.value;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.open;
import static com.codeborne.selenide.Selenide.screenshot;
import static com.codeborne.selenide.Selectors.*;
import static com.codeborne.selenide.WebDriverRunner.*;
import com.codeborne.selenide.WebDriverRunner;
import com.codeborne.selenide.*;

Thank you for an answer in advance.
P.S. I saw the selenium 3.2 was published out there. Selenide maven repository uses the lower version 3.0.1 right now.

@Cotola you can use like above or can use like this:

// here '*' imports all static methods in that class
import static com.codeborne.selenide.Selenide.*;

import static com.codeborne.selenide.Condition.*;

Thank you @anilreddy!
(Sorry in my comments asterisk was not shown properly until I use "Insert code").
These two lines you mention don't cover com.codeborne.selenide.CollectionCondition.size method
and com.codeborne.selenide.WebDriverRunner.* library. And I still need to know the Names of the libraries to import.
It is just one way to automatically show proposals in eclipse by default. I suppose another way is to configure the eclipse itself.

At last I have found in selenide javadoc all package names to import:

import com.codeborne.selenide.*;
import com.codeborne.selenide.collections.*;
import com.codeborne.selenide.commands.*;
import com.codeborne.selenide.conditions.*;
import com.codeborne.selenide.ex.*;
import com.codeborne.selenide.impl.*;
import com.codeborne.selenide.junit.*;
import com.codeborne.selenide.logevents.*;
import com.codeborne.selenide.proxy.*;
import com.codeborne.selenide.testng.*;
import com.codeborne.selenide.testng.annotations.*;
import com.codeborne.selenide.webdriver.*;

But we still need static import of FULL LIST OF CLASSES to write fluent code (make the code more readable). For example we need to import static com.codeborne.selenide.Selenide.* to make possible use of $ and $$ methods.

@Cotola I have just gave you 2 examples.

Thank you!
I see that I need more Java core and eclipse knowledge. :)

i can't seem to switch to an angular MatDialog, does someone know how?

@NickMeert-dev can you share the example so that I can help you with that.

Was this page helpful?
0 / 5 - 0 ratings