1
windows_before = driver.window_handles
driver.find_element_by_css_selector("[href='http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2']").click()
windows_after = driver.window_handles
new_window =
driver.switch_to_window(new_window)
driver.close()
driver.switch_to_window(windows_before)

Please can someone tell me how can I get the id of new window. I have windows_before = 'CDwindow-8b18d716-650e-4793-ac69-10532978004c' than I have list with id of old and new windows ['CDwindow-8b18d716-650e-4793-ac69-10532978004c', 'CDwindow-1b199b20-c50e-4301-bbea-9f0f8faa2902']

How can I get the element from my list that not match with windows_before?

Thank you

1 Answer 1

1

This will pick the first window in the list that is not windows_before, as long as windows_before is a string and not a list.

new_window = [x for x in windows_after if x != windows_before][0]
Sign up to request clarification or add additional context in comments.

2 Comments

it works, thank you very much but what means [0] there?
[0] gets the first item in the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.