Selenium Python PhantomJS截图问题

时间:2017-04-17 16:36:37

标签: python selenium phantomjs screenshot

我需要一些特定网站的帮助来渲染,我一直在努力制作一个好的截图,但实际上我不能,然后我注意到它不是我的代码,它是html或css ,但是,请问,任何人都可以获得这个网站的好截图吗? (http://www.entel.pe

当我获得截图时,它会呈现为响应式,但这是一个非常糟糕的选择,但分布非常糟糕。

这是我的代码

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
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import unittest, time, re


class TestPruebaHomeValoresEnlaces(unittest.TestCase):
    def setUp(self):
        dcap = dict(DesiredCapabilities.PHANTOMJS)
        dcap["phantomjs.page.settings.userAgent"] = (
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36")
        #self.driver = webdriver.PhantomJS(executable_path=r'D:\Projects\webdrivers\phantomjs-2.1.1-windows\bin\phantomjs.exe')
        self.driver = webdriver.PhantomJS(desired_capabilities=dcap, executable_path=r'D:\Projects\webdrivers\phantomjs-2.1.1-windows\bin\phantomjs.exe', service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false'])
        self.driver.set_window_size(1280, 720)
        self.base_url = "http://www.entel.pe"
        time.sleep(5)
        self.verificationErrors = []
        self.accept_next_alert = True


    def test_prueba_home_valores_enlaces(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.save_screenshot('screenshot.png')

    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e:
            return False
        return True

    def is_alert_present(self):
        try:
            self.driver.switch_to_alert()
        except NoAlertPresentException as e:
            return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally:
            self.accept_next_alert = True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)


if __name__ == "__main__":
    unittest.main()

这是我的python设置

$ pip freeze
Appium-Python-Client==0.24
beautifulsoup4==4.5.3
html5lib==0.999999999
sauceclient==0.2.1
selenium==3.3.3
six==1.10.0
webencodings==0.5.1
xmlrunner==1.7.7

我希望有人可以获得一个很好的截图并告诉我如何。感谢

0 个答案:

没有答案