Last active
May 27, 2019 05:00
-
-
Save bbchriscesar/167bd61cfe53c76c2f9662bf6521a8f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from selenium import webdriver | |
| from selenium.webdriver.support import expected_conditions as EC | |
| from selenium.webdriver.support.ui import WebDriverWait | |
| from selenium.webdriver.common.by import By | |
| from selenium.webdriver.common.action_chains import ActionChains as chains | |
| import os.path | |
| import time | |
| options = webdriver.ChromeOptions() | |
| options.add_argument("--kiosk") # For Mac | |
| options.add_argument("--start-maximized") # For Linux | |
| driver = webdriver.Chrome(executable_path=r'/Users/christiannec/Documents/ChromeDriver/chromedriver', options=options) | |
| def moveToElement(xpath): | |
| target = driver.find_element_by_xpath(xpath) | |
| target.location_once_scrolled_into_view | |
| time.sleep(2) | |
| def moveToElements(xpath, index): | |
| target = driver.find_element_by_xpath(xpath)[index] | |
| target.location_once_scrolled_into_view | |
| time.sleep(2) | |
| def findElementByXpath(xpath): | |
| driver.find_element_by_xpath(xpath).click() | |
| time.sleep(2) | |
| def findElementsByXpath(xpath, index): | |
| driver.find_elements_by_xpath(xpath)[index].click() | |
| time.sleep(2) | |
| def waitForElement(xpath): | |
| wait = WebDriverWait(driver, 30) | |
| element = wait.until(EC.element_to_be_clickable((By.XPATH, xpath))) | |
| time.sleep(2) | |
| def hoverToElement(xpath): | |
| time.sleep(1) | |
| actions = chains(driver) | |
| element_hover = driver.find_element_by_xpath(xpath) | |
| actions.move_to_element(element_hover).perform() | |
| time.sleep(2) | |
| def hoverToElements(xpath, index): | |
| time.sleep(1) | |
| actions = chains(driver) | |
| element_hover = driver.find_elements_by_xpath(xpath)[index] | |
| actions.move_to_element(element_hover).perform() | |
| time.sleep(2) | |
| def takeScreenshot(filename): | |
| time.sleep(1) | |
| driver.save_screenshot(filename) | |
| time.sleep(1) | |
| locales = ['en-US'] | |
| for locale in locales: | |
| path = "/Users/christiannec/Documents/PythonOutput/" + locale | |
| if not os.path.exists(path): | |
| os.makedirs(path) | |
| driver.get("https://www.google.com/") | |
| driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment