Skip to content

Instantly share code, notes, and snippets.

@budioktaviyan
Created May 19, 2019 05:31
Show Gist options
  • Save budioktaviyan/561cf08bcca1f5df7f351c34e83515b7 to your computer and use it in GitHub Desktop.
Save budioktaviyan/561cf08bcca1f5df7f351c34e83515b7 to your computer and use it in GitHub Desktop.
package id.kotlin.situng
import org.apache.commons.io.FileUtils
import org.openqa.selenium.OutputType
import org.openqa.selenium.TakesScreenshot
import org.openqa.selenium.chrome.ChromeDriver
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
fun main() {
System.setProperty("webdriver.chrome.driver", "${System.getProperty("user.dir")}/chromedriver")
var driver: ChromeDriver? = null
for (i in 0 until 9) {
driver = ChromeDriver().apply {
manage().window().fullscreen()
get("https://pemilu2019.kpu.go.id/#/ppwp/hitung-suara/")
}
Thread.sleep(2000)
val source = (driver as TakesScreenshot).getScreenshotAs(OutputType.FILE)
val path = "${System.getProperty("user.dir")}/${SimpleDateFormat("yyyyMMddHHmmSS").format(Date())}.situng.png"
FileUtils.copyFile(source, File(path))
Thread.sleep(8000)
driver.close()
}
driver?.quit()
}
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3.31")
application
}
repositories {
jcenter()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.seleniumhq.selenium:selenium-java:3.141.59")
implementation("org.seleniumhq.selenium:selenium-firefox-driver:3.141.59")
implementation("org.seleniumhq.selenium:htmlunit-driver:2.35.1")
implementation("commons-io:commons-io:2.5")
}
application {
mainClassName = "id.kotlin.situng.AppKt"
}
@budioktaviyan
Copy link
Author

Full source can be clone through this link https://github.com/budioktaviyan/situng-captor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment