2

I have an array of selenium.webdriver.remote.webelement.WebElements. In order to loop through theses elements and keep the session, I need to open each element in a new tab, extract the data, then close the tab. I see THAT there is a way to open a new tab, but it requires a url: How to open a new tab using Selenium WebDriver in Java? . Is there any way to command click these elements?

SOURCE: https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html

    def click(self) -> None:
        """Clicks the element."""
        self._execute(Command.CLICK_ELEMENT)
joey
  • 115
  • 8

1 Answers1

1

To open a new tab with selenium you can send CONTROL + T keys in Windows OS.
Tab can be closed with CONTROL + W keys on Windows OS.
Like this:

#open tab
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't') 

For OSX COMMAND + T and COMMAND + W can be used accordingly.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • This is the correct answer... as a sidenote sometimes dataframes prevent you from opening a new tab – joey Aug 03 '21 at 02:18