All Downloads are FREE. Search and download functionalities are using the official Maven repository.

selenium_steps_support.service.frame_switchers.FrameSwitcher.kt Maven / Gradle / Ivy

There is a newer version: 5.3.5
Show newest version
package selenium_steps_support.service.frame_switchers

import com.google.common.base.Splitter
import org.openqa.selenium.WebDriver
import selenium_steps_support.service.elem_locators.ElementLocatorService
import java.util.regex.Pattern

object FrameSwitcher {

    private val SPLITTER = Splitter.on(Pattern.compile("\n|\r\n"))
            .trimResults()
            .omitEmptyStrings()

    fun switchToFrame(topDriver: WebDriver,
                      frameLocator: String): WebDriver {
        val frameLocatorParts = SPLITTER.split(frameLocator).toList()

        var driver = topDriver
        for (frameLocatorPart in frameLocatorParts) {
            val element = ElementLocatorService.locateElement(driver, frameLocatorPart)
                    ?: throw RuntimeException("failed to find element [$frameLocatorPart]")
            driver = driver.switchTo().frame(element)
        }

        return driver
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy