Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support.ui import Select
- import unittest, time, re
- self.driver = webdriver.PhantomJS()
- self.driver.implicitly_wait(30)
- self.base_url = "https://login.example.com"
- driver = self.driver
- driver.get(self.base_url)
- all_cookies = self.driver.get_cookies()
- # It prints out all cookies and values just fine
- for cookie in all_cookies
- print cookie['name'] + " --> " + cookies['value']
- # Set cookies to driver
- for s_cookie in all_cookies:
- c = { s_cookie['name'] : s_cookie['value']}
- # This is where it's throwing an error saying "Can only set Cookies for current domain
- driver.add_cookie(c)
- ...
- import unittest
- from selenium.webdriver.common.by import By
- from selenium import webdriver
- __author__ = 'Saifur'
- class CookieManagerTest(unittest.TestCase):
- def setUp(self):
- self.driver = webdriver.PhantomJS("E:\working\selenium.python\selenium\resources\phantomjs.exe")
- self.driver.get("https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/")
- self.driver.find_element(By.ID, "Email").send_keys("userid")
- self.driver.find_element(By.ID, "next").click()
- self.driver.find_element(By.ID, "Passwd").send_keys("supersimplepassword")
- self.driver.find_element(By.CSS_SELECTOR, "[type='submit'][value='Sign in']").click()
- self.driver.maximize_window()
- def test(self):
- driver = self.driver
- listcookies = driver.get_cookies()
- for s_cookie in listcookies:
- # this is what you are doing
- c = {s_cookie['name']: s_cookie['value']}
- print("*****The partial cookie info you are doing*****n")
- print(c)
- # Should be done
- print("The Full Cookie including domain and expiry infon")
- print(s_cookie)
- # driver.add_cookie(s_cookie)
- def tearDown(self):
- self.driver.quit()
- url = 'http://domainname.com'
- url2 = 'http://domainname.com/page'
- USER = 'superAwesomeRobot'
- PASS = 'superSecretRobot'
- # initiates your browser
- driver = webdriver.PhantomJS()
- # browses to your desired URL
- driver.get(url)
- # searches for the user or email field on the page, and inputs USER
- driver.find_element_by_id("email").send_keys(USER)
- # searches for the password field on the page, and inputs PASS
- driver.find_element_by_id("pass").send_keys(PASS)
- # finds the login button and click you're in
- driver.find_element_by_id("loginbutton").click()
- driver.get(url2)
- driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement