Skip to content

Instantly share code, notes, and snippets.

@RajeshKrSahoo
Created August 24, 2023 15:43
Show Gist options
  • Save RajeshKrSahoo/f519caef7b71ae2e73ded0073a170891 to your computer and use it in GitHub Desktop.
Save RajeshKrSahoo/f519caef7b71ae2e73ded0073a170891 to your computer and use it in GitHub Desktop.
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
service = Service(executable_path=r"C:\Users\VT151UP\OneDrive - EY\Documents\chromedriver.exe")
options = webdriver.ChromeOptions()
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--start-maximized")
options.add_argument('user-agent={0}'.format(user_agent))
# driver = webdriver.Chrome(r'chromedriver', options=options)
driver = webdriver.Chrome(service=service, options=options)
action = ActionChains(driver)
time.sleep(1)
driver.get('https://playalberta.ca/lottery')
html = driver.page_source
print(html)
time.sleep(50)
try:
# firstLevelMenu = driver.find_element_by_xpath('//*[@id="section-3"]/div/div/div/div/div[1]/div/div')
# action.move_to_element(firstLevelMenu).perform()
# time.sleep(3)
# secondLevelMenu = driver.find_element(by=By.XPATH, value='//*[@id="section-3"]/div/div/div/div/div[1]/div/div')
# secondLevelMenu.click()
se=driver.find_element(by=By.XPATH, value='''//*[@id="section-3"]/div/div/div/div/div[1]/div/div/div[1]/div[2]''')
print(se.text)
time.sleep(3)
# driver.close()
## for closing current browser opened!
except Exception as e:
## for quiting all the session active on driver
# driver.quit()
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment