Hi,
i’m trying to run a test in which i’ve created two Chrome WebDriver istances, but i got a problem while using WebUI methods when i have more tabs opened in the browsers.
In order, i run this code:
WebUI.openBrowser('')
WebUI.maximizeWindow()
WebUI.navigateToUrl("www.example.it")
WebDriver regularChromeDriver = DriverFactory.getWebDriver()
CustomKeywords.'utility.CommonUtilities.setRegularDriver'(regularChromeDriver)
CustomKeywords.'utility.CommonUtilities.minimizeBrowser'(CustomKeywords.'utility.CommonUtilities.getRegularDriver'())
ChromeOptions options = new ChromeOptions()
options.addArguments('--incognito')
WebDriver incognitoDriver = new ChromeDriver(options)
DriverFactory.changeWebDriver(incognitoDriver)
CustomKeywords.'utility.CommonUtilities.setIncognitoDriver'(incognitoDriver)
WebUI.maximizeWindow()
WebUI.navigateToUrl("www.example2.it")
CustomKeywords.'utility.CommonUtilities.minimizeBrowser'(CustomKeywords.'utility.CommonUtilities.getIncognitoDriver'())
DriverFactory.changeWebDriver(regularChromeDriver)
WebUI.maximizeWindow()
where CustomKeywords.'utility.CommonUtilities contains two static variables referred to the web drivers and the method minimizeBrowser(WebDriver driver) that simply executes this line
driver.manage().window().setPosition(new Point(-2000, 0));
Now, after running the code written above, the test continues interacting with the elements in the first browser and then in the same Chrome instance another tab is opened, so the test executes the following code:
WebUI.switchToWindowIndex(WebUI.getWindowIndex() + 1)
WebUI.waitForElementVisible(WebElement, 10, FailureHandling.STOP_ON_FAILURE)
WebUI.setText(WebElement, variable)
WebUI.delay(4)
WebUI.click(WebElement)
The problem is: everything is ok when switching the windows - the windows index is 1 ( because of the second tab in the browser ) - but when the waitForElementVisible (or waitForElementPresent, or also many other methods like switchToDefaultContent) is executing the window index becomes 0 and the browser switches to the first tab. If i click manually the other tab during WaitFor method, it continues to switch to the first tab.
I am using Katalon Studio Enterprise 9.7.2.