1from selenium import webdriver
2from selenium.webdriver.common.keys import Keys
3
4driver = webdriver.Firefox()
5driver.get("http://www.python.org")
6assert "Python" in driver.title
7elem = driver.find_element_by_name("q")
8elem.clear()
9elem.send_keys("pycon")
10elem.send_keys(Keys.RETURN)
11assert "No results found." not in driver.page_source
12driver.close()
13
1
2import org.openqa.selenium.By;
3import org.openqa.selenium.Keys;
4import org.openqa.selenium.WebDriver;
5import org.openqa.selenium.WebElement;
6import org.openqa.selenium.firefox.FirefoxDriver;
7import org.openqa.selenium.support.ui.WebDriverWait;
8import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
9import java.time.Duration;
10
11public class HelloSelenium {
12
13 public static void main(String[] args) {
14 WebDriver driver = new FirefoxDriver();
15 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
16 try {
17 driver.get("https://google.com/ncr");
18 driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
19 WebElement firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3>div")));
20 System.out.println(firstResult.getAttribute("textContent"));
21 } finally {
22 driver.quit();
23 }
24 }
25}
26