Chris Cooper
Chris Cooper

Reputation: 17594

How can I view the Javascript Window ID of my window? For use with Selenium select_window()

I am trying to select a newly-opened window using Selenium, and the select_window() method requires its WindowID.

I have tried using the window's title, as other places have suggested, and turned on Selenium's debug mode, as the documentation suggests to see a window.open intercept, but neither option seems to have worked.

Is there just some simple javascript command I can enter in the new window's console to view the window ID?

Upvotes: 2

Views: 3014

Answers (3)

user3487861
user3487861

Reputation: 350

For Safe Use

Perform

1.$sel->get_all_window_titles();

2.$sel->get_all_window_ids();

3.$sel->get_all_window_names();

From this Either we can use [select_window id/title/name] Simple.

Upvotes: 0

Chris Cooper
Chris Cooper

Reputation: 17594

I ended up extracting the link URL from the anchor, and simply navigated to that URL instead of opening a new window.

Upvotes: 0

Amey
Amey

Reputation: 8548

So there are two things, as I am not sure what is your exact scenario.

So considering you have opened the new window, while doing so, you can define the window id. So for example:-

$sel->open_window("http://www.google.com", "Chris Cooper");
$sel->select_window("Chris Cooper");

Or if the new window is popup(not explicitly opened by you), you could simply use

$sel->select_pop_up();

Upvotes: 1

Related Questions