Created
December 27, 2019 02:23
-
-
Save BooookStore/802905f48d48de76945ef41cba148895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.jupiter.api.Test | |
import org.openqa.selenium.By | |
import org.openqa.selenium.WebDriver | |
import org.openqa.selenium.chrome.ChromeOptions | |
import org.openqa.selenium.remote.RemoteWebDriver | |
import org.openqa.selenium.support.ui.ExpectedConditions | |
import org.openqa.selenium.support.ui.WebDriverWait | |
import java.net.URL | |
class RemoteWebDriverExample { | |
@Test | |
fun remoteWebBrowserExample() { | |
var driver: WebDriver? = null | |
try { | |
// connect SeleniumServer | |
val options = ChromeOptions() | |
driver = RemoteWebDriver(URL("http://localhost:4444/wd/hub"), options) | |
// search 'filter' on kotlin reference page | |
with(driver) { | |
get("https://kotlinlang.org/docs/reference/") | |
// input search word | |
findElement(By.className("search-button")).click() | |
findElement(By.className("ais-search-box--input")).sendKeys("filter") | |
// wait for asynchronous result | |
WebDriverWait(driver, 10) | |
.until(ExpectedConditions.visibilityOfElementLocated(By.className("ais-infinite-hits--item"))) | |
// print result | |
findElements(By.className("ais-infinite-hits--item")).apply { | |
println("hit count is $size") | |
forEach { | |
println(it.text) | |
} | |
} | |
} | |
} finally { | |
driver?.close() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment