Created
May 19, 2019 05:31
-
-
Save budioktaviyan/561cf08bcca1f5df7f351c34e83515b7 to your computer and use it in GitHub Desktop.
Robot kotlin script, inspired from https://gist.github.com/edwin/49be66615237a506498c72ccff1cb6c9
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
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() | |
} |
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
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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full source can be clone through this link https://github.com/budioktaviyan/situng-captor