Skip to content
Advertisement

How to open a link without knowing its URL in new tab using python selenium

I wanted to click a link in facebook group post which has href attribute as “#” but when we click on it that href attribute will automatically change to particular URL so I just wanted to click on link so that it will open in new tab.

Sorry I don’t have any code to explain this scenario.

Advertisement

Answer

Since you didn’t provide nor code nor a link to that page I answered it with some example code on how to open a link in a new tab:

JavaScript

Anyway this is it: you use ActionChains to control+click (open in new tab) the link. With that you can perform every complex operation. A list of available actions/methods can be found here.

EDIT: Ah, if then (I guess) you want to move from a tab to another you can easily do it like this:

JavaScript

Where tabs is a zero-based list (tabs[0] is the first tab, tabs[1] the second and so on…)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement