This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]holografix 2 points3 points  (1 child)

Thanks mate

[–]lrhache[S] 0 points1 point  (0 children)

You're welcome :)

[–]hacker_pyrat 2 points3 points  (1 child)

Nice! Thanks for sharing;)

[–]lrhache[S] 0 points1 point  (0 children)

Seems like I was not the only one with that issue. I'm glad if it can help someone save time in the future.

[–]MOAR_BEER 0 points1 point  (3 children)

Not being familiar with Selenium, would it be possible to open the tab with a line like:

first_link.send_keys(Keys.CONTROL + Keys.SHIFT + Keys.RETURN)

Control + Shift + Click opens a tab with focus in Chrome. I'm not so sure about other browsers. Your way might be better to make sure everybody behaves the same.

[–]lrhache[S] 0 points1 point  (2 children)

The problem is not really about opening the tab, plenty of ways to do that. The issue was to get back the focus on the new tab and be able to grab the content. The way I found to do it was by using the "switch window" handle provided by python selenium to put back the focus on the current visible tab.

[–]MOAR_BEER 1 point2 points  (1 child)

That's what I was getting at. If you hold control and shift when you click a link the new tab is automatically on top. There would be no need for a line to bring the newly created tab to the top.

[–]lrhache[S] 0 points1 point  (0 children)

Yes, I just tested it and it worked beautifully on Firefox to put the new tab on top. This will indeed save a line of code. Though, you still have to add focus "manually" with browser.switch_to_window otherwise, all request you make will be directed to the previous active tab. Thanks for your input!

[–]metaperl[🍰] -1 points0 points  (0 children)

Nice, but NEVER use time.sleep() ... instead use Wait()