Selenium Python



Selenium Python


from selenium import webdriver
import time

browser = webdriver.Chrome('C:\chromedriver\chromedriver')

browser.get('http://www.google.com')

time.sleep(2)

search_input = browser.find_element_by_name('q')
search_input.send_keys('hello world')

time.sleep(2)

search_btn = browser.find_element_by_css_selector('input[type="submit"]')
search_btn.click()

'''


'''	


AWS Lambda Selenium runs on Python 3.7

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import json
import boto3
from datetime import datetime

ec2 = boto3.client('ec2')

def lambda_handler(event, context):
    options = Options()
    options.binary_location = '/opt/headless-chromium'
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')

    driver = webdriver.Chrome('/opt/chromedriver',chrome_options=options)
    
    driver.get('https://tutorialsninja.com/demo/')
    title = driver.title

    driver.close();
    driver.quit();
    
    if (title == "Your Store"):
        print("Success")
        response = ec2.describe_images(Owners=['self'])
        new = max(image['CreationDate'] for image in response['Images'] if image['Name'].startswith('AD-CCC-SAML'))
        print('new',new)
        filtered_images = [image for image in response['Images'] if image['CreationDate'] == new]
        print('filtered_images',filtered_images)
        
    else:
        print("No")

    response = {
        "statusCode": 200,
        "body": title,
        "filtered_image": filtered_images
    }

    return response