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)

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the correct answer... as a sidenote sometimes dataframes prevent you from opening a new tab
0

if you are using Selenium 4 and later versions. try this code

driver.switch_to.new_window('tab')
wait = WebDriverWait(driver, 20)
driver.get(linkURL)

Comments

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.