Skip to content

Instantly share code, notes, and snippets.

@BooookStore
Last active December 24, 2019 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BooookStore/73ca44696a6f716fc392404121909103 to your computer and use it in GitHub Desktop.
Save BooookStore/73ca44696a6f716fc392404121909103 to your computer and use it in GitHub Desktop.
import org.junit.jupiter.api.Test
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
class Examples {
@Test
fun kotlinHomePageSectionTextGetExample() {
// indicate chromedriver place
System.setProperty("webdriver.chrome.driver", "/opt/WebDriver/bin/chromedriver")
// instantiate webdriver from chromedriver
// and add options headless mode argument
// all options seen this site: https://peter.sh/experiments/chromium-command-line-switches/
val options = ChromeOptions().apply {
addArguments("--headless")
}
val driver: WebDriver = ChromeDriver(options)
// access kotlin home page and get section-content text by class name
driver.get("https://kotlinlang.org")
val sectionContent = driver.findElement(By.className("section-content"))
// output result
println(sectionContent.text)
// close chrome
driver.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment