Facebook
From Cream Butterfly, 3 Years ago, written in Python.
This paste is a reply to Untitled from x - view diff
Embed
Download Paste or View Raw
Hits: 120
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. import time
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. from selenium.webdriver.common.by import By
  7.  
  8.  
  9. driver = webdriver.Chrome()
  10. user_login_field = driver.find_element_by_name("user[username]")
  11. user_password_field = driver.find_element_by_name("user[password]")
  12. open_login_button = driver.find_element_by_xpath("//*[@id='nav']/div/ul[2]/li[4]/a")
  13.  
  14. correct_user_login = "JaneAhonen"
  15. correct_user_password = "nastepnymrazemciepokonam"
  16. login_button_again = driver.find_element_by_xpath("//*[@id='nav']/div/ul[2]/li[4]/div/div/ul/li[1]/form/fieldset/p/input")
  17.  
  18. driver.get("https://wykop.pl/")
  19.  
  20.  
  21. def accept_privacy_frame():
  22.         WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='cmp-iframe']")))
  23.         driver.switch_to.frame(driver.find_element_by_xpath("//*[@id='cmp-iframe']"))
  24.         time.sleep(5)
  25.         WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div/div/div/div[3]/div[2]/button")))
  26.         driver.find_element_by_xpath("/html/body/div/div/div/div/div/div[3]/div[2]/button").click()
  27.         driver.switch_to.default_content()
  28.  
  29. def login_user_with_correct_data(login, password, correct_login, correct_password, loggin_button):
  30.         open_login_button.click()
  31.         login.send_keys(correct_login)
  32.         password.send_keys(correct_password)
  33.         loggin_button.click()
  34.  
  35.  
  36. accept_privacy_frame()
  37. login_user_with_correct_data(user_login_field,user_password_field,correct_user_login,correct_user_password,login_button_again) 
  38.