示例#1
0
def dump_page_source(dump_name, webdriver, source_dump_path):
    print("going to save page and screenshot called %s in folder %s" %
          (dump_name, source_dump_path))
    with open(os.path.join(source_dump_path, dump_name + '.html'), 'wb') as f:
        f.write(webdriver.page_source.encode('utf8'))
    webdriver.save_screenshot(
        os.path.join(source_dump_path, dump_name + '.jpg'))
示例#2
0
文件: driver.py 项目: leospol/webdiff
def shot(cap, url, ads=None):
    webdriver = webdriver.Remote(hubUrl,
                            desired_capabilities=cap,
                            proxy=proxy)
    webdriver.set_window_size(1024, 800)
    webdriver.get(url)
    if ads:
        sizeJs = "elm=document.getElementById(\"%s\");\
                  elm.style.display=\"block\";elm.style.width=\"%s px\";\
                  elm.style.height=\"%s px\";elm.style.overflow=\"hidden\";"
        for ad in ads:
            elm = webdriver.find_element_by_id(ad["id"])
            if ad["size"] != (elm.size["width"], elm.size["height"]):
                webdriver.execute_script(sizeJs % (ad["id"], ad["size"][0],
                                         ad["size"][1]))

    try:
        ads = webdriver.execute_script("return pozice;")
    except selenium.common.exceptions.WebDriverException:
        ads = []
    for ad in ads:
        elm = webdriver.find_element_by_id(ad["id"])
        ad["size"] = elm.size["width"], elm.size["height"]
        ad["location"] = elm.location["x"], elm.location["y"]
    for dId in debugIds:
        webdriver.execute_script(removeDebug % dId)

    _, filename = tempfile.mkstemp()
    webdriver.save_screenshot(filename)
    data = open(filename).read()
    os.remove(filename)
    return data, ads
示例#3
0
def shot(webdriver, browser, testId, buildId):
    proxy = ServerProxy(uploadUrl)
    webdriver.set_window_size(1024, 800)

    ret = proxy.remoteFile.read(libs.path.uploadPath(testId, browser,
                                                     "original",
                                                     "ads.pickle"))
    if ret["status"] == 200:
        originExists = True
    else:
        originExists = False

    if not originExists:
        ads1 = loads(ret["data"].data)
        if ads1:
            sizeJs = "elm=document.getElementById(\"%s\");\
                      elm.style.display=\"block\";\
                      elm.style.width=\"%s px\";elm.style.height=\"%s px\";\
                      elm.style.overflow=\"hidden\";"
            for ad in ads1:
                elm = webdriver.find_element_by_id(ad["id"])
                if ad["size"] != (elm.size["width"], elm.size["height"]):
                    webdriver.execute_script(sizeJs % (ad["id"], ad["size"][0],
                                                       ad["size"][1]))

    try:
        ads2 = webdriver.execute_script("return pozice;")
    except selenium.common.exceptions.WebDriverException:
        ads2 = []
    for ad in ads2:
        elm = webdriver.find_element_by_id(ad["id"])
        ad["size"] = elm.size["width"], elm.size["height"]
        ad["location"] = elm.location["x"], elm.location["y"]
    for dId in debugIds:
        webdriver.execute_script(removeDebug % dId)

    _, filename = tempfile.mkstemp()
    webdriver.save_screenshot(filename)
    data = open(filename).read()
    os.remove(filename)
    adsPickled = dumps(ads2)
    if originExists:
        proxy.remoteFile.write(libs.path.uploadPath(testId, browser, buildId,
                                                    "build.png"),
                               Binary(data), False)
        proxy.remoteFile.write(libs.path.uploadPath(testId, browser, buildId,
                                                    "ads.pickle"),
                               Binary(adsPickled), False)
    else:
        proxy.remoteFile.write(libs.path.uploadPath(testId, browser,
                                                    "original",
                                                    "original.png"),
                               Binary(data), False)
        proxy.remoteFile.write(libs.path.uploadPath(testId, browser,
                                                    "original",
                                                    "ads.pickle"),
                               Binary(adsPickled), False)
def take_screenshot(webdriver, file_name="sample.png"):
    """
    @param webdriver: WebDriver handler.
    @type webdriver: WebDriver
    @param file_name: Name to label this screenshot.
    @type file_name: str 
    """
    if isinstance(webdriver, WebDriver):
        base64_data = webdriver.get_screenshot_as_base64()
        screenshot_data = base64.decodestring(base64_data)
        screenshot_file = open(file_name, "w")
        screenshot_file.write(screenshot_data)
        screenshot_file.close()
    else:
        webdriver.save_screenshot(filename)
def take_screenshot(webdriver, file_name = "sample.png"):
    """
    @param webdriver: WebDriver handler.
    @type webdriver: WebDriver
    @param file_name: Name to label this screenshot.
    @type file_name: str 
    """
    if isinstance(webdriver, WebDriver):
        base64_data = webdriver.get_screenshot_as_base64()
        screenshot_data = base64.decodestring(base64_data)
        screenshot_file = open(file_name, "w")
        screenshot_file.write(screenshot_data)
        screenshot_file.close()
    else:
        webdriver.save_screenshot(filename)
示例#6
0
def get_grades(u, p):
    webdriver.get(url)
    print('page loaded')
    id_number = webdriver.find_element_by_xpath(
        "/html/body/table/tbody/tr[2]/td/table/tbody/tr/td[2]/form/table/tbody/tr[3]/td/input"
    )
    id_number.send_keys(u)
    password = webdriver.find_element_by_xpath(
        "/html/body/table/tbody/tr[2]/td/table/tbody/tr/td[2]/form/table/tbody/tr[4]/td/input"
    )
    password.send_keys(p)
    enter = webdriver.find_element_by_xpath(
        '/html/body/table/tbody/tr[2]/td/table/tbody/tr/td[2]/form/table/tbody/tr[5]/td/input[1]'
    ).send_keys(Keys.RETURN)
    time.sleep(1)
    print('logged in')
    webdriver.find_element_by_xpath(
        '/html/body/form/table/tbody/tr[2]/td/table/tbody/tr[3]/td/a'
    ).send_keys(Keys.RETURN)
    time.sleep(1)
    print('extracting grades')
    webdriver.get('http://sis.benilde.edu.ph/sisv2/CurrentEnrollmentRecord')
    time.sleep(1)

    now = datetime.now()
    dt_string = now.strftime("%d-%m-%Y_%H-%M-%S")

    grades = webdriver.find_element_by_xpath('//*[@id="content"]')

    location = grades.location
    size = grades.size
    file_name = '%s_grades.png' % (dt_string)
    file_path = './grades/%s' % (file_name)
    webdriver.save_screenshot(file_path)
    x = location['x']
    y = location['y']
    width = location['x'] + size['width']
    height = location['y'] + size['height']
    im = Image.open(file_path)
    im = im.crop((int(x), int(y), int(width), int(height)))
    im.save(file_path)
    print('grades saved as %s' % file_path)
示例#7
0
def handle(conn):
    global request_p
    global webdriver
    recv = conn.recv(2048).decode()
    request = request_p.fullmatch(recv)
    if not (request):
        conn.send('error:mal formato'.encode())
        return conn.close()
    else:
        request = request.groupdict()
    pet, param, dest = request['pet'], base64.b64decode(
        request['param'].encode()), request['dest']
    if pet == 'mutt':
        param = param.decode()
        webdriver.set_window_size(480, 800)
        req = 'http://127.0.0.1:8080/mutt?text=%s' % param
        print('Requesting: ' + req)
        webdriver.get(req)
        webdriver.save_screenshot(dest)
        conn.send(('succes:' + dest).encode())
    elif pet == 'ss':
        param = param.decode()
        webdriver.set_window_size(1280, 720)
        webdriver.get(param)
        print('Requesting: ' + param)
        webdriver.save_screenshot(dest)
        conn.send(('succes:' + dest).encode())
    elif pet == 'meme':
        param = pickle.loads(param)
        query = '&'.join([key + '=' + param[key] for key in param])
        req = 'http://127.0.0.1:8080/meme?%s' % query
        print('Requesting: ' + req)
        webdriver.get(req)
        webdriver.save_screenshot(dest)
        conn.send(('succes:' + dest).encode())
    elif pet == 'profile':
        param = base64.b16encode(param).decode()
        webdriver.set_window_size(1000, 1000)
        req = 'http://127.0.0.1:8080/profile?pkfile=%s' % param
        print('Requesting: ' + req)
        webdriver.get(req)
        webdriver.save_screenshot(dest)
        conn.send(('succes:' + dest).encode())
    else:
        conn.send('error:peticion no encontrada'.encode())
    conn.close()
示例#8
0
 def save_screenshot(self):
     screenshot_path = self.get_current_time() + '.png'
     webdriver.save_screenshot(screenshot_path)
     return screenshot_path
示例#9
0
# -*-coding:utf-8-*-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# 创建PhantomJS浏览器对象
webdriver = webdriver.PhantomJS(
    executable_path=r'D:\phantomjs-2.1.1-windows\bin\phantomjs.exe')

webdriver.get('https://www.douban.com/')
# 截屏
webdriver.save_screenshot('douban.png')

captcha = raw_input('验证码:\n')
# 输入账号
webdriver.find_element_by_id('form_email').send_keys('13960942437')

# 输入密码
webdriver.find_element_by_id('form_password').send_keys('wo951127')

# 输入验证码
webdriver.find_element_by_id('captcha_field').send_keys(captcha)

#点击登陆
webdriver.find_element_by_class_name('bn-submit').click()

webdriver.save_screenshot('login.png')
示例#10
0
 def take_Screenshot_A(self,driver):
     fileName = str(round(time.time() * 1000)) + ".png"
     dir = "/Users/aravindanathdm/Desktop/"
     driver.save_screenshot(dir+fileName)
示例#11
0
def take_screenshot(webdriver,filename,url,w=1024,h=768):
    webdriver.get(url)
    webdriver.set_window_size(w,h)
    return webdriver.save_screenshot(filename)
示例#12
0
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
#driver = webdriver.Chrome(executable_path=r"C:\chromedriver.exe")



desiredCapabilities = DesiredCapabilities.CHROME.copy()
chromeOptionsRemote = webdriver.ChromeOptions()
chromeOptionsRemote.add_argument("--start-maximized")
chromeOptionsRemote.add_argument("--disable-session-crashed-bubble")

initRemoteDriver = webdriver.Remote(options=chromeOptionsRemote, command_executor='http://localhost:4444/wd/hub/', desired_capabilities=desiredCapabilities)
print(initRemoteDriver.current_url)


#driver = webdriver.Firefox(executable_path=r"C:\geckodriver.exe")
#driver.maximize_window()
webdriver.get("https://www.duckduckgo.com")
webdriver.delete_all_cookies()
title = webdriver.title
print(title)
assert title == "DuckDuckGo — Prywatność — jeszcze prostsza.", "Tytuł nie zgadza się z " + title

wpisz = webdriver.find_element_by_id("search_form_input_homepage")
szukaj = webdriver.find_element_by_id("search_button_homepage")
wpisz.send_keys("pogoda Lublin")
szukaj.click()
webdriver.save_screenshot("screnshot.png")
#driver.close()
示例#13
0
password.send_keys(your_password_here)
submit = webdriver.find_element_by_tag_name('form')
submit.submit()

# By passing the turn-on notifications
time.sleep(5)
noti = webdriver.find_element_by_xpath('//button[text()="Not Now"]')
noti.click()
# Navigaating to accounts page
acc = webdriver.find_element_by_xpath(
    '//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[3]/a/span'
)
acc.click()
time.sleep(5)
# taking screenshot
webdriver.save_screenshot("unfollowing.png")
text = extract('unfollowing.png')
num = re.findall('\d+', text)
ra = int(num[1])

# Un-following
time.sleep(2)
for i in range(ra):
    follow = webdriver.find_element_by_xpath(
        '//*[@id="react-root"]/section/main/div/header/section/ul/li[3]/a')
    follow.click()
    time.sleep(3)
    webdriver.find_element_by_xpath(
        "/html/body/div[3]/div/div[2]/ul/div/li[1]/div/div[3]/button").click()
    confirm = webdriver.find_element_by_xpath('//button[text()="Unfollow"]')
    confirm.click()