0

This script used to run before the 31th of August. But it shows these three errors now.

I have tried uninstall the pillow, or use the particular version, but it still not work,like this : Pyautogui screenshot - NameError: name 'Image' is not defined

Does anyone have idea on this ?

"EC" is not defined, "array" is not defined, "Image" is not defined

These are relative 2 function.

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
EnzoMolion
  • 949
  • 8
  • 25
jay su
  • 1
  • 1
  • 3
  • where have you imported the EC? From what it looks, it seems EC is a module. – user2906838 Sep 08 '21 at 04:39
  • oh, my bad, add the import module information – jay su Sep 08 '21 at 04:46
  • even if add these... from selenium.webdriver.support import expected_conditions as EC import array import image.............the final one can't work – jay su Sep 08 '21 at 04:47
  • I don't yet see, still the EC defined. – user2906838 Sep 08 '21 at 04:52
  • 1
    `from selenium.webdriver.support import expected_conditions as EC` this should be imported to get rid off `"EC" is not defined` other two you'd have to handle it separately – cruisepandey Sep 08 '21 at 05:04
  • how about image? I just don't know why it can work before from selenium.webdriver.support import expected_conditions as EC, import array these two add. – jay su Sep 08 '21 at 05:26
  • actually it can work before these three error show up, I want to know why, maybe some module can't work know? – jay su Sep 08 '21 at 05:34

1 Answers1

-1

Use the following code to comments

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='DraftEditor-editorContainer']/div[@class='notranslate public-DraftEditor-content' and starts-with(@aria-describedby, 'placeholder')]"))).send_keys("type the comment here")