Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created May 31, 2021 16:51
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
username = "Your_username_within_double_quotes"
accessToken = “Your_access_token_in_quotes”
gridUrl = "hub.lambdatest.com/wd/hub"
desired_cap = {
'platform' : "win10",
'browserName' : "chrome",
'version' : "67.0",
"resolution": "1024x768",
"name": "LambdaTest python google search test ",
"build": "LambdaTest python google search build",
"network": True,
"video": True,
"visual": True,
"console": True,
}
url = "https://"+username+":"+accessToken+"@"+gridUrl
print("Initiating remote driver on platform: "+desired_cap["platform"]+" browser: "+desired_cap["browserName"]+" version: "+desired_cap["version"])
# driver = webdriver.Chrome()
driver = webdriver.Remote(
desired_capabilities=desired_cap,
command_executor= url
)
# driver.get("file:///G:/jsalert/jsalerts.html")
driver.get("https://pynishant.github.io/")
time.sleep(7)
try:
driver.find_element_by_id('simple').click()
WebDriverWait(driver, 5).until(EC.alert_is_present(), 'Timed out waiting for simple alert to appear')
alert = driver.switch_to.alert
time.sleep(4)
alert.accept()
print("alert accepted")
except TimeoutException:
print("no alert")
time.sleep(7)
print("simple alert test passed")
print("Now running prompt alert test")
try:
driver.find_element_by_id('prompt').click()
WebDriverWait(driver, 5).until(EC.alert_is_present(), 'Timed out waiting for prompt alert to appear')
alert = driver.switch_to.alert
time.sleep(7)
alert.send_keys('560085')
time.sleep(7)
print("printing alert text")
print(alert.text)
alert.accept()
print("alert accepted")
except TimeoutException:
print("no alert")
time.sleep(5)
print("prompt alert test passed")
print("Now running confirm alert test")
try:
driver.find_element_by_id('confirm').click()
WebDriverWait(driver, 5).until(EC.alert_is_present(), 'Timed out waiting for prompt alert to appear')
alert = driver.switch_to.alert
print("printing alert text from confirmation alert")
print(alert.text)
time.sleep(7)
alert.accept()
print("alert accepted")
except TimeoutException:
print("no alert")
time.sleep(5)
print("confirmation alert test passed")
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment