1

I am trying to automate a test case using Java, Selenium and Chrome Driver but I have not been able to navigate to the newly opened tab. I can see that the page opens but Selenium's focus does not move to the new tab.

I have tried a number of things: each of these points were tried on their own

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL, Keys.PAGE_DOWN);
element = driver.switch_to_window(element.driver.window_handles[1]);
element.sendKeys(Keys.CONTROL +"\t");
new Actions(driver).sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(driver.findElement(By.tagName("html")),Keys.NUMPAD2).build().perform();
element = driver.findElement(By.xpath("//bdi[contains(text(),'Open SQL Console')]"));
        ScriptUtils.waitFor(DELAY);
        supa.startMeasurement("40_Open_SQL_Console");
        element.click();
        System.out.println("Step 40 " );

        ScriptUtils.waitFor(DELAY);

``` java        
element = driver.switch_to_window(element.driver.window_handles[1]);
element.sendKeys(Keys.CONTROL +"\t");
new Actions(driver).sendKeys(driver.findElement(By.tagName("html")), Keys.CONTROL).sendKeys(driver.findElement(By.tagName("html")),Keys.NUMPAD2).build().perform();

I have even tried to go directly to the page but without luck.

driver.get ("https://mo-xxxx.mo.xxxx.corp:51043/xxxx/xxxxxa/cst/catalog/index.html?target=sqlconsole&databaseid=C119");

I can tell that I am on the same page because I can find an element on the current page.

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(@data-xxxx-ui, '__editor')]"}

The element can easily be found outside of java/selenium so I know it is there.

Lana
  • 15
  • 8
  • Have you tried anything like what's outlined here: https://stackoverflow.com/questions/12729265/switch-tabs-using-selenium-webdriver-with-java ? – Katie.Sun Aug 29 '19 at 15:31
  • Yes, I have tried that as well, Katie. Tried a number of other suggestions from here but deleted them as I found that they did not work. I still get the same error message that it can not find an element on the new page (but can for the previous page). – Lana Aug 29 '19 at 15:37
  • when you debug using the method in the link from the above comment, does the tab show in the list created by `ArrayList tabs2 = new ArrayList (driver.getWindowHandles());`? – Katie.Sun Aug 29 '19 at 15:40
  • I am using Eclipse and have not found an easy way to debug. New to Java, Eclipse and Selenium. Let try to figure out that. – Lana Aug 29 '19 at 15:50
  • Ok. I would highly recommend figuring that out before you do anything else! It will make things much easier. – Katie.Sun Aug 29 '19 at 16:00
  • I wish it was 20 years ago and I was still using Cobol on the mainframe! I did manage to figure it out using the what was outlined in your original answer Katie. I will mark it as the best answer. Thank you. – Lana Aug 29 '19 at 16:30

0 Answers0