How to open a new window using the frame of a robot, selenium?

My test page has a link that opens by default in a new TAB. I need to open a link and check some values ​​on a newly opened page. Since I found that selenium does not support tabbed browsing, so I am trying to open the link in a new window, but it still does not work. I implemented a python function to store the SHIFT key (I did this before for CTRL and it works), and then I called the "click" function, but the link still opens in a new tab

from robot.libraries.BuiltIn import BuiltIn
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

class CustomSeleniumLibrary(object):
    def __init__(self):
        self.driver = None
        self.library = None
        self.ac = None

    def get_library_instance(self):
        if self.library is None:
            self.library = BuiltIn().get_library_instance('ExtendedSelenium2Library')
        return self.library

    def get_action_chain(self):
        if self.ac is None:
            self.ac = ActionChains(self.get_library_instance()._current_browser())
        return self.ac

def hold_shift(self):
        actionChain = self.get_action_chain()
        actionChain.key_down(Keys.SHIFT)
        actionChain.perform()

Keyword robot

Open project detail
     wait until element is visible  ${LINK_TO_PROJECT}
     ${project}=  get text  ${LINK_TO_PROJECT}
     hold shift
     click element   ${LINK_TO_PROJECT}
     #sleep  2s
     #release shift
     element should contain   //h3  Project Details: ${project}

, .., . ( ), , DOM .. !

+4
1

, :

current = driver.current_window_handle
driver.find_element_by_css_selector('a').click() # use own selector
new_tab = [tab for tab in driver.window_handles if tab != current][0]
driver.switch_to.window(new_tab)
# do some actions
driver.close()
driver.switch_to.window(current)

( , ...), :

link = driver.find_element_by_css_selector('a')
driver.execute_script('arguments[0].target="_self";', link)
+1

Source: https://habr.com/ru/post/1672739/


All Articles