From 3b7b15e8ce1fcd61f37372196d4802556bdb0069 Mon Sep 17 00:00:00 2001 From: Hammad1007 Date: Thu, 28 Dec 2023 14:51:45 +0500 Subject: [PATCH] Testing using selenium --- _project_starter_/selenium/backgroundcolor.py | 29 +++++++++++++++++++ .../selenium/headingisvisible.py | 26 +++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 _project_starter_/selenium/backgroundcolor.py create mode 100644 _project_starter_/selenium/headingisvisible.py diff --git a/_project_starter_/selenium/backgroundcolor.py b/_project_starter_/selenium/backgroundcolor.py new file mode 100644 index 0000000..eca07e9 --- /dev/null +++ b/_project_starter_/selenium/backgroundcolor.py @@ -0,0 +1,29 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() + +# chrome_options.add_argument("--headless") # Run headless if needed +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) + +driver.get('http://127.0.0.1:5500/_project_starter_/') + +# Find the element you want to check the background color for +element = driver.find_element(By.TAG_NAME, 'body') # Replace with your element's ID or any other locator + +# Get the CSS value for the 'background-color' property of the element +background_color = element.value_of_css_property('background-color') + +# Print the background color +print(f"Background color of the element: {background_color}") +time.sleep(5) + +driver.quit() diff --git a/_project_starter_/selenium/headingisvisible.py b/_project_starter_/selenium/headingisvisible.py new file mode 100644 index 0000000..4673f49 --- /dev/null +++ b/_project_starter_/selenium/headingisvisible.py @@ -0,0 +1,26 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +# chrome_options.add_argument("--headless") # Run headless if needed +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) + +driver.get('http://127.0.0.1:5500/_project_starter_/') + +# Find the element with a specific tag name (e.g., 'h1' for heading) +heading_element = driver.find_element(By.TAG_NAME, 'h1') + +# Print the text content of the heading element +print(heading_element.text) + +time.sleep(5) + +driver.quit()