I want to iteratively click each item in a structure of links and open each link in a new tab. I also want to get and print the title of each tab.

example site footer links

    package basics;
    import java.util.Iterator;
    import java.util.Set;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    public class Naukri {
        public static void main(String[] args) throws InterruptedException {
            System.setProperty("webdriver.chrome.driver", "C://chromedriver_win32//chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            WebElement s = driver.findElement(By.xpath("//*[@class = 'footer anchorList']//*[@class='wrap']"));

            // Attempt to open each link in a new tab
            for (int i=0;i<s.findElements(By.tagName("a")).size(); i++) {
                String clickonlinkTab = Keys.chord(Keys.CONTROL, Keys.ENTER);
            // Attempt to print all the open tab names.
            Set<String> ListofLinks = driver.getWindowHandles();
            Iterator<String> it = ListofLinks.iterator();
            while (it.hasNext()) {
  • Could you please explain more on this?
    Feb 6, 2019 at 19:19
  • I want to open all 69 links in new tabs and going forward want to print all those 69 links title links on my console Feb 6, 2019 at 19:24
  • Explain more on issue side also. It helps others to understand where it went wrong.
    Feb 6, 2019 at 19:27
  • 1
    @AshutoshSingh. That's quite overkill. It's like using cannon to kill a fly -- the whole process will be pretty slow and resource consuming. Why do you use Selenium for that?
    – dzieciou
    Feb 6, 2019 at 19:29
  • 1
    Suggestion: Be Clear with question, Clearly explain what you are trying to do. what you tried and where you got struck. also provide required samples/examples/URLs
    Feb 6, 2019 at 20:11


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.