R
R
r1mple2022-01-07 23:43:25
Python
r1mple, 2022-01-07 23:43:25

Why doesn't selenium open links in a new tab?

There was such a problem, for some reason selenium does not open links in new tabs.
Here is the code that worked before.

for group in tqdm(groups):
            try:
                self.ac.move_to_element(group).click().perform()
                time.sleep(2)
                self.driver.switch_to.window(self.driver.window_handles[1])
                time.sleep(2)
                urls.append(self.driver.current_url)

                time.sleep(2)

                self.driver.close()

                time.sleep(2)

                self.driver.switch_to.window(self.driver.window_handles[0])

            except Exception as e:  # it's just too many exceptions can happen here, catching every one would be too long to write.
                print(e)
                continue            # sry for everyone reading that. P.S. I'm not ashamed.

        return urls

when debugging, I realized that selenium opens the link in the same tab, although there was no such behavior before.
Mb, this is due to the fact that I updated the driver version, now it is 97 something there, before it was 96 something there.
it would be possible to solve the problem by simply returning to the previous page by pressing certain keys, but there is a problem, a site with a huge feed, I scroll it to the very end, thereby loading all the elements into the array, otherwise selenium simply does not see them, because they are not loaded yet, then I need to get a link to each of the groups, there are no links to groups in the html on the feed page, because of this I have to go to the group page and get a link to it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question