0

I'm new to Selenium and trying to work with multiple windows.

I'm able to open the initial page and display its title in console. The title of the main page will print.

Then, I locate the element to click on.

When clicking on it, the page is supposed to load in the new tab and I need to print out new title of the page.

However, nothing happens. Only new tab is opened and nothing happens afterwords.

This is the code:

public class WindowHandlerPractice {

static ChromeOptions options;
static WebDriver driver;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\eugeneg\\local-eclipse-workspace\\webdrivers\\chromedriver\\chromedriver.exe");
    options = new ChromeOptions();
    options.setExperimentalOption("useAutomationExtension", false);

    driver = new ChromeDriver(options);
    driver.get("https://www.msn.com");
    driver.manage().window().maximize();

    driver.findElement(By.xpath("//div[@class='mestripescrollfix']//ul[@role='menubar']//li[2]")).click();
    //driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    System.out.println(driver.getTitle());
    Set<String> windHand = driver.getWindowHandles();
    Iterator<String> it = windHand.iterator();
    String parentid = it.next();
    String childid = it.next();
    driver.switchTo().window(childid);
    System.out.println(driver.getTitle());
}

}

Where is my mistake?

gene
  • 2,098
  • 7
  • 40
  • 98

1 Answers1

0

I just tried the above scenario and it worked for me. Could you try with the below changes

  • Avoid setting chromeoptions
  • Use latest chrome and chromedriver