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.
1 Like
Hi there, and thanks for posting in the Katalon community!
To help you faster, please review our guide on Custom Keyword here: Introduction to custom keywords in Katalon Studio | Katalon Docs. Double-checking the steps and configurations might resolve the issue.
If the doc doesn’t help, feel free to provide more details, and a community member will assist you soon. Thanks for being a part of our community!
Best,
Albert Le
@albert.vu You should have a developer take a look. What @esibilio.wk is describing sounds like a bug. The problem I have (or anyone else on the outside) is setting up enough code and data to replicate/test the issue.
2 Likes
Thank you @Russ_Thomas and @esibilio.wk for sharing about this issue with us. I’m going to loop in @xuan.tran from our Studio team here so that she can take a look.
Thanks,
Albert
Oh, and as @esibilio.wk is using KSE, you’ll be able to get faster support from our Product Support team by submitting a ticket via the link below:
https://katalon-inc.my.site.com/katalonhelpcenter/s/
You saw waitForElementVisible
failed; OK, I understand it. Then, you inferred the cause of the failure was the window index being 0; I doubt it.
How did you know that the window index becomes 0 ? Could you show us any evidence of your finding? Any error log did the waitForElementVisible
emit? Did the message clearly tell that “the window index becomes 0”?
Hi @kazurayam,
I know that the cause of the failure is the window index because the element I’m looking for is in the second tab opened in the browser, but Katalon automatically switches to the first tab (index 0) when waitForElementVisible
is executing. Therefore, waitForElementVisible
fails because it doesn’t find the element I pass as a parameter. I’ve discovered that the window index is changing during the execution of waitForElementVisible
by printing the current window index using WebUI.getCurrentWindowIndex()
:
WebUI.switchToWindowIndex(WebUI.getWindowIndex() + 1)
System.out.println("Window Index after the switch: " + WebUI.getWindowIndex()) //Here the window index is correct, equal to 1.
WebUI.waitForElementVisible(WebElement, 10, FailureHandling.CONTINUE_ON_FAILURE)
System.out.println("Window Index after the wait: " + WebUI.getWindowIndex()) //Here the window index is incorrect because it changes to 0, even after the previous line where I switched to index 1.
WebUI.setText(WebElement, variable)
WebUI.delay(4)
WebUI.click(WebElement)
As I’ve mentioned, if I try to click manually on the second tab while waitForElementVisible
is running, the browser automatically switches back to the first tab because Katalon has changed the window index to 0. I wondered if the window index might be a sort of synchronized variable, but I tried keeping the same number of tabs open in both browsers and nothing changed. I believe this is a problem related to Katalon.
Hi @albert.vu,
do you advise me to open a ticket, or should I just wait for a response in this thread?
Could you show the code where you declare the name "WebElement"
?
Is it the class name of org.openqa.selenium.WebElement
?
Or is it a variable declared like "def WebElement = ...."
?
No, I’ve written ‘WebElement’ just as an example; I use TestObject
from com.kms.katalon.core.testobject.TestObject
. I declare the variable as an attribute of a class:
TestObject toCercaImposta= new TestObject().addProperty('xpath', ConditionType.EQUALS, "//input[@title='Cerca in Imposta']")
This variable is used in the following method in the same class (the code where the problem is):
def void cercaImposta(String nome) {
WebUI.switchToWindowIndex(WebUI.getWindowIndex() + 1)
WebUI.waitForElementVisible(toCercaImposta, 10, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.setText(toCercaImposta, nome)
WebUI.delay(4)
WebUI.click(toResultRicerca) //Here is another variable declared as 'toCercaImposta'
}
The class is under the package ‘Keywords’ and i call the method from a ‘Test Case’ under the package ‘Test Cases’ using ‘CustomKeywords’.
‘Test Case’ code:
...
CustomKeywords.'package_name.ClassName.cercaImposta'(String name)
...
‘package_name’ and ‘ClassName’ are just an example.
It is difficult for me to reproduce this problem on my machine, so I would quit this topic.
1 Like
Hi @esibilio.wk,
Yes, if possible, please also create a ticket here in case other forum members cannot come up with a solution to your issue.
Thanks,
Albert
Hi @esibilio.wk,
Thank you for letting us know your issue. Just let you know that my team is investigating on your issue. I would like to summarize your issue context as follows:
- Users run a script to open a Chrome browser under
regularChromeDriver
and an incognito Chrome browser
- The browser under
regularChromeDriver
in executing time will have 2 tabs. When the user is in window index 0 and tries to switch to window index 1, it switches successfully.
- However, when performing any actions on the windows, it switches back to the first tab, although users intentionally click to the second.
Please help confirm if my understanding is correct. Otherwise, please share any project/report/videos if possible.
From this brief, we can reproduce this case. We observed:
- After switching to the second tab, it quickly switched back to the first tab → this caused the executing window index to seem to become 0.
- When doing any methods on the second tab, it switches to the first tab and tries to apply the method that can not be passed
We will review more and decide next actions once you can verify this is correct to your case. Thank you!
Hi all,
This issue has been solved in v10.0.0. Please help check and use it. I will process to close this thread, if any new problem, please raise it in the new thread. Thank you!