Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何检查密码隐藏字符?_Python 3.x_Selenium_Python Unittest - Fatal编程技术网

Python 3.x 如何检查密码隐藏字符?

Python 3.x 如何检查密码隐藏字符?,python-3.x,selenium,python-unittest,Python 3.x,Selenium,Python Unittest,您好,我需要有关检查密码隐藏字符的帮助。如果密码的长度与密码隐藏字符的长度相同,我必须测试密码字段。没有OCR有什么办法可以做到吗。 我知道密码短语及其长度。现在我需要检查隐藏字符是否与密码短语长度相同。 现在,我的ide是剪切web元素,计算封面字符(黑圈而不是密码),然后检查这个单词的长度是否和密码短语相同。还有别的办法吗? THX为-3分。这是我的代码,如果有人有同样的问题。希望这有帮助 from selenium import webdriver from PIL import Imag

您好,我需要有关检查密码隐藏字符的帮助。如果密码的长度与密码隐藏字符的长度相同,我必须测试密码字段。没有OCR有什么办法可以做到吗。 我知道密码短语及其长度。现在我需要检查隐藏字符是否与密码短语长度相同。 现在,我的ide是剪切web元素,计算封面字符(黑圈而不是密码),然后检查这个单词的长度是否和密码短语相同。还有别的办法吗?
THX为-3分。这是我的代码,如果有人有同样的问题。希望这有帮助

from selenium import webdriver
from PIL import Image
import time
import cv2


password = '12345678'
driver = webdriver.Chrome('C:\chromedriver\chromedriver.exe')
driver.get('mysite.com')
time.sleep(2)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
element = driver.find_element_by_xpath('//*[@id="password"]')
location = element.location
size = element.size
driver.save_screenshot("PageImage.png")
x = location['x']
y = location['y']
width = location['x']+size['width']
height = location['y']+size['height']
im = Image.open('PageImage.png')
im = im.crop((int(x), int(y), int(width), int(height)))
im.save('pass.png')
driver.quit()
passSlika = cv2.imread('pass.png', 0)
cv2.imwrite('pass.png', passSlika)
th, threshed = cv2.threshold(passSlika, 100, 255, cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)
cnts = cv2.findContours(threshed, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]
s1 = 3
s2 = 20
xcnts = []
for cnt in cnts:
    if s1<cv2.contourArea(cnt) <s2:
        xcnts.append(cnt)

#Minus one is because eye in design is one more dot
if (len(xcnts)-1 == len(password)):
    print('the same')
从selenium导入webdriver
从PIL导入图像
导入时间
进口cv2
密码='12345678'
driver=webdriver.Chrome('C:\chromedriver\chromedriver.exe')
driver.get('mysite.com')
时间。睡眠(2)
驱动程序。通过xpath('/*[@id=“password”]')查找元素。发送密钥(密码)
element=driver。通过xpath('/*[@id=“password”]”查找\u元素
位置=元素。位置
大小=元素大小
driver.save_屏幕截图(“PageImage.png”)
x=位置['x']
y=位置['y']
宽度=位置['x']+尺寸['width']
高度=位置['y']+尺寸['height']
im=Image.open('PageImage.png'))
im=im.裁剪((int(x)、int(y)、int(宽度)、int(高度)))
im.save('pass.png')
driver.quit()
passSlika=cv2.imread('pass.png',0)
cv2.imwrite('pass.png',passSlika)
th,threshed=cv2.阈值(passSlika,100255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
cnts=cv2.findContours(脱粒,cv2.RETR\u列表,cv2.CHAIN\u近似简单)[-2]
s1=3
s2=20
xcnts=[]
对于cnt中的cnt:
如果s1