硒保存画布的空白图像

时间:2019-02-18 11:22:34

标签: python-3.x testing selenium-webdriver

我正在加载以下画布元素。

<canvas height="522" width="810" id="chart-1" style="display: block; width: 900px; height: 580px; touch-action: none; outline: none; background: white; cursor: auto;" tabindex="8888"></canvas>

,我正在尝试将其存储为PNG。我已尝试关注

    from selenium import webdriver
    import time
    import base64

    driver = webdriver.Chrome()
    driver.get("http://localhost:4200/agreements")
    table_rows = driver.find_element_by_xpath("/html/body/app-root/app-agreements/div/table/tbody/tr[1]")
    table_rows.click()

    #Works perfectly fine till here !

    time.sleep(2)
    canvas = driver.find_element_by_xpath('//*[@id="chart-1"]')

    # get the canvas as a PNG base64 string
    canvas_base64 = driver.execute_script("return arguments[0].toDataURL('image/png').substring(21);", canvas)
    # decode
    canvas_png = base64.b64decode(canvas_base64)

    # save to a file
    with open(r"canvas.png", 'wb') as f:
        f.write(canvas_png)
  

基本上,我在画布上加载了一个图表,当用户单击具有不同数据集的表中的一行时,该图表就会加载。我想看看是否有任何变化。但是它只将第一张图像保存为空。

     

点击表格前后的网址:

http://localhost:4200/documents

http://localhost:4200/documents/e894de0e-349a-4b25-8fbb-68f6fce8ac06;documentType=NonDisclosureAgreement

0 个答案:

没有答案