Skip to content

Instantly share code, notes, and snippets.

@dfucci
Created May 9, 2022 14:06
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 dfucci/bff9a198958305f7ed90cecb917c3cf8 to your computer and use it in GitHub Desktop.
Save dfucci/bff9a198958305f7ed90cecb917c3cf8 to your computer and use it in GitHub Desktop.
Examples of using Selenium for GUI testing in Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.webelement import WebElement
import unittest
import time
driver = webdriver.Chrome()
#wikipedia example
driver.get("http://www.wikipedia.org")
driver.find_element_by_id("js-link-box-en").click()
time.sleep(2)
driver.find_element_by_id("searchInput").send_keys("tiger")
time.sleep(2)
driver.find_element_by_id("searchInput").send_keys(Keys.ENTER)
assert "Tiger - Wikipedia" == driver.title
assert "Tiger" == driver.find_element_by_id("firstHeading").text
print("all good")
time.sleep(3)
#amazon example
driver.get("http://www.amazon.com")
time.sleep(2)
driver.find_element_by_id("twotabsearchtextbox").send_keys("Galactic Purple Dual Sense")
driver.find_element_by_id("twotabsearchtextbox").send_keys(Keys.ENTER)
driver.find_element_by_xpath("//*[text() = 'PlayStation DualSense Wireless Controller – Galactic Purple']").click()
pricestring : str = driver.find_element(By.ID, "priceblock_ourprice").text[1:]
assert (float(pricestring) > 70)
print("price is fine")
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment