Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created May 12, 2021 16:48
Show Gist options
  • Save muditlambda/5dd4cf4343d90bd94ce0c4dd3931e1fb to your computer and use it in GitHub Desktop.
Save muditlambda/5dd4cf4343d90bd94ce0c4dd3931e1fb to your computer and use it in GitHub Desktop.
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
import time
from datetime import datetime
class DragTest(unittest.TestCase):
def setUp(self):
# configuration to test in the cloud using lambdaTest
username = "your user name"
accessToken = "Your access token"
gridUrl = "hub.lambdatest.com/wd/hub"
desired_cap = {
'platform': "win10",
'browserName': "firefox",
'version': "67.0",
"resolution": "1024x768",
"name": "LambdaTest python selenium wait testing automation",
"build": "Implicit Wait",
"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"])
self.driver = webdriver.Remote(
desired_capabilities=desired_cap,
command_executor=url
)
# self.driver = webdriver.Firefox()
def test_selenium_wait(self):
driver = self.driver
driver.maximize_window()
# defining condition for implicit waits - we have set 10 seconds
driver.implicitly_wait(10)
driver.get('https://pynishant.github.io/Selenium-python-waits.html')
pageLoadedClock = datetime.now()
current_time_after_page_loaded = pageLoadedClock.strftime("%H:%M:%S")
print("Time after page load and before clicking the Try it button=", current_time_after_page_loaded)
driver.find_element(By.XPATH, '//button[text()="Try it"]').click()
# this won't FAIL with implicit time set
try:
# printing time to demonstrate waits
pageLoadClock = datetime.now()
current_time = pageLoadClock.strftime("%H:%M:%S")
print("Time before starting polling for CLICK ME Button =", current_time)
driver.find_element(By.XPATH, '//button[text()="CLICK ME"]').click()
pageLoadClock = datetime.now()
current_time = pageLoadClock.strftime("%H:%M:%S")
print("Time after CLICK ME was found =", current_time)
except Exception as e:
print(e)
def tearDown(self):
# closes the driver
self.driver.quit()
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment