Python Forum
Selenium - How to position yourself in a new tab
Thread Rating:
  • 3 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium - How to position yourself in a new tab
#1
Hello,

I have been working with Selenium as I mentioned here an admin and it is amazing. Only that I have a doubt, when I am in a tab and there is a link which displays a new window by itself, I do not know how to position myself with Selenium. I would appreciate if you could help me. I leave them images so that they understand me better. Thank you!


There everything works correctly, I can get the selectors, everything. The problem comes when I click Selenium to the Facebook button, then it does not find the selectors of the window that opened...
[Image: avvpNfx.png]
  [Image: ZnLb1IZ.png]
 
I forgot to mention, I'm using Firefox, the Google Chrome driver put me many problems.
 
Reply
#2
Quote:The problem comes when I click Selenium to the Facebook button, then it does not find the selectors of the window that opened...
You mean how to switch to a popup window? You have to switch to the new window with selenium. Something like...
main_window_handle = None
while not main_window_handle:
    main_window_handle = driver.current_window_handle
driver.find_element_by_xpath(u'//a[text()="click here"]').click()
signin_window_handle = None
while not signin_window_handle:
    for handle in driver.window_handles:
        if handle != main_window_handle:
            signin_window_handle = handle
            break
driver.switch_to.window(signin_window_handle)
driver.find_element_by_xpath(u'//input[@id="id_1"]').send_keys(user_text_1)
driver.find_element_by_xpath(u'//input[@value="OK"]').click()
driver.find_element_by_xpath(u'//input[@id="id_2"]').send_keys(user_text_2)
driver.find_element_by_xpath(u'//input[@value="OK"]').click()
driver.switch_to.window(main_window_handle) #or driver.switch_to_default_content()
http://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.window_handles

http://www.seleniumhq.org/docs/03_webdri...and-frames
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,626 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020