该脚本曾经在 8 月 31 日之前运行。但它现在显示了这三个错误。
我试过卸载枕头,或使用特定版本,但它仍然无法正常工作,如下所示: Pyautogui screenshot - NameError: name 'Image' is not defined
有人对此有想法吗?
“EC”未定义,“数组”未定义,“图像”未定义
这些是相对的 2 功能。
from selenium import webdriver
from HTMLTestRunner import HTMLTestRunner
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import array
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
import unittest, time, re, os, sys
import pyautogui
def located_element(self, locator):
wait = WebDriverWait(self.driver,30)
element = wait.until(EC.presence_of_element_located((locator)))
return element
def getClippedImage(driver, canvas, x, y, w, h):
### Get a clipped image from canvas using context.getImageData.
data = driver.execute_script(
"var canvas= arguments[0];
var x=arguments[1];
var y=arguments[2];
var w=arguments[3];
var h=arguments[4];
var context = canvas.getContext(‘2d‘);
var dataObj= context.getImageData(x, y, w, h);
var data = dataObj.data;
return data;"
,canvas, x, y, w, h)
data_bytes = array.array('B', data).tostring()
im = Image.fromstring("RGBA", (w, h), data_bytes)
return im