from selenium import webdriver
import time
from PIL import Image
import os
from pathlib import Path
my_file = Path('k:/zhusc/2.png')
if my_file.exists():
os.remove(my_file)
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def wait_for_you(myDynamicElement):
try:
element=WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.XPATH,myDynamicElement))
)
finally:
driver.find_element_by_xpath(myDynamicElement).click()
url="https://vip.gxrc.com/Public/Phone/6C73242B-DE0C-490B-A715-3DF7BCED7825"
driver=webdriver.Chrome('k:/zhusc/chromedriver.exe')
driver.get(url)
driver.maximize_window()
myDynamicElement='/html/body/img'
try:
element=WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.XPATH,myDynamicElement))
)
except:
pass
driver.get_screenshot_as_file('k:/zhusc/2.png')
e = driver.find_element_by_xpath('/html/body/img')
location = e.location
size = e.size
left = e.location['x']
top = e.location['y']
right = e.location['x'] + e.size['width']
bottom = e.location['y'] + e.size['height']
im = Image.open('k:/zhusc/2.png')
im = im.crop((left, top, right, bottom))
im.save('k:/zhusc/2.png')