Last active
April 15, 2025 02:48
-
-
Save ejreyme/0f4601e8fd73f6762c3eec1c4af5ad54 to your computer and use it in GitHub Desktop.
with(this) { name = "ejreyme"; seleniumLevel = 100 }
This file contains hidden or 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.openqa.selenium.chrome.ChromeDriver | |
import org.openqa.selenium.By | |
import org.openqa.selenium.Keys | |
import java.time.Duration | |
fun main() { | |
// 1 start the session | |
val driver = ChromeDriver() | |
// 2 take action on browser | |
driver.get("https://selenium.dev") | |
// 3. request browser information | |
val title = driver.title | |
println("The title of the page is: $title") | |
// 4. establish waiting strategy | |
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)) | |
// 5. find an element | |
val textBox = driver.findElements(By.name("my-text")) | |
val submitButton = driver.findElement(By.cssSelector("button")) | |
// 6. take action on element | |
textBox.first().sendKeys("Hello Selenium!") | |
submitButton.click() | |
// 7. request element information | |
val message = driver.findElements(By.id("message")) | |
val value = message.first().text | |
// 8. end the session | |
driver.quit() | |
} | |
fun blogSearchSteps(driver: ChromeDriver) { | |
val blogLink = driver.findElement(By.xpath("//*[@id=\"main_navbar\"]/ul/li[6]/a/span")) | |
blogLink.click() | |
val searchBox = driver.findElement(By.xpath("//*[@id=\"docsearch-1\"]/button")) | |
searchBox.click() | |
val modalSearchBox = driver.findElement(By.xpath("//*[@id=\"docsearch-input\"]")) | |
modalSearchBox.sendKeys("Selenium") | |
modalSearchBox.sendKeys(Keys.ENTER) | |
val pageHeader = driver.findElement(By.xpath("/html/body/div/div[1]/div/main/div/h1")) | |
println("The page header is: ${pageHeader.text}") | |
assert(pageHeader.text.contains("Selenium")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment