执行 Selenium 显式等待时 Katalon 中的 GroovyCastException
GroovyCastException in Katalon when performing Selenium explicit wait
我正在尝试在 Katalon(使用 Groovy)中执行显式等待。我有以下代码:
// wait on page change to "Dashboard"
WebDriverWait dashboardChangeWait = new WebDriverWait(driver, 3)
/* This is causing the following Exception :
* - GroovyCastException : Attempt to cast 'true' with class 'java.lang.Boolean' to class
* 'org.openqa.selenium.WebElement'
* */
WebElement element = dashboardChangeWait.until(
ExpectedConditions.textToBe(By.cssSelector('.breadcrumb-item.active'), "DASHBOARD"))
这给了我 GroovyCastException
。我知道 WebDriverWait.until
采用 Function
(是的,JavaScript-like 编码!)参数,ExpectedConditions.textToBe
returns a ExpectedCondition<Boolean>
和 until
的签名是 V org.openqa.selenium.support.ui.FluentWait.until(Function<Object, Object<V>> arg0)
。有没有办法在 Katalon 中执行这种类型的等待,从而避免这个问题?
你非常接近。 ExpectedConditions方法textToBe()
定义如下:
public static ExpectedCondition<java.lang.Boolean> textToBe(By locator, java.lang.String value)
An expectation for checking WebElement with given locator has specific text
Parameters:
locator - used to find the element
value - used as expected text
Returns:
Boolean true when element has text value equal to @value
所以你只需要将 return 类型改为 boolean
而不是 WebElement
如下:
Boolean status = dashboardChangeWait.until(ExpectedConditions.textToBe(By.cssSelector('.breadcrumb-item.active'), "DASHBOARD"))
我正在尝试在 Katalon(使用 Groovy)中执行显式等待。我有以下代码:
// wait on page change to "Dashboard"
WebDriverWait dashboardChangeWait = new WebDriverWait(driver, 3)
/* This is causing the following Exception :
* - GroovyCastException : Attempt to cast 'true' with class 'java.lang.Boolean' to class
* 'org.openqa.selenium.WebElement'
* */
WebElement element = dashboardChangeWait.until(
ExpectedConditions.textToBe(By.cssSelector('.breadcrumb-item.active'), "DASHBOARD"))
这给了我 GroovyCastException
。我知道 WebDriverWait.until
采用 Function
(是的,JavaScript-like 编码!)参数,ExpectedConditions.textToBe
returns a ExpectedCondition<Boolean>
和 until
的签名是 V org.openqa.selenium.support.ui.FluentWait.until(Function<Object, Object<V>> arg0)
。有没有办法在 Katalon 中执行这种类型的等待,从而避免这个问题?
你非常接近。 ExpectedConditions方法textToBe()
定义如下:
public static ExpectedCondition<java.lang.Boolean> textToBe(By locator, java.lang.String value)
An expectation for checking WebElement with given locator has specific text
Parameters:
locator - used to find the element
value - used as expected text
Returns:
Boolean true when element has text value equal to @value
所以你只需要将 return 类型改为 boolean
而不是 WebElement
如下:
Boolean status = dashboardChangeWait.until(ExpectedConditions.textToBe(By.cssSelector('.breadcrumb-item.active'), "DASHBOARD"))