저는 BrowserStack에서 사용할 ActionChain 함수를 검색했습니다. Facebook에서 앱을 제거하고 싶습니다. 내가 작업 한 후에는 find_element_by_id 및 find_element_by_name과 같은 일반적인 셀렌 함수로 요소를 찾고 클릭하여 제거 할 수 없다는 것을 알고있었습니다. 그래서, 나는 어떤 이미지 프로세싱을 사용하기로 결정했다. 나는 페이지에서 응용 프로그램의 아이콘을 찾고 그것에 커서를 옮기고 싶다. 그 후 X 버튼이 나타납니다. 표시되면 클릭하고 싶습니다. ActionChain을 사용하여 아이콘의 위치를 찾은 다음 커서를 해당 위치로 이동했습니다. 그러나 커서는 짧은 시간 동안 아이콘에 선다. ActionChain의 클릭 기능이 작동하지 않습니다. 아래 코드를 추가했습니다. ActionChain의 이러한 커서 이동 및 클릭 기능에 대해 도움을받을 수 있다면 기쁜 마음입니다.커서를 움직여 Selenium WebDriver를 클릭하십시오. ActionChains
라이브러리 :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
import numpy as np
from PIL import Image
from skimage import data
from skimage.feature import match_template
from selenium.webdriver import ActionChains
ActionChains (드라이버) .move_by_offset (XA, 나중에) .click() (수행)
코드 :.
driver.get("https://www.facebook.com/settings?tab=applications")
time.sleep(5)
driver.save_screenshot('/Users/***/Desktop/ssfordelete.png')
ssfordelete = Image.open("/Users/***/Desktop/ssfordelete.png")
ssfordeleteGray = ssfordelete.convert('L')
ssfordeleteGrayNp = np.asarray(ssfordeleteGray)
allow = Image.open("/Users/***/Desktop/browserStack/allow.png")
allowGray = allow.convert('L')
allowGrayNp = np.asarray(allowGray)
resultdelete1 = match_template(ssfordeleteGrayNp, allowGrayNp)
dij = np.unravel_index(np.argmax(resultdelete1), resultdelete1.shape)
sizeofallowx=allowGrayNp.shape[0]
sizeofallowy=allowGrayNp.shape[1]
xa, ya = dij[::-1]
xa = xa + (sizeofallowx/2)
ya = ya + (sizeofallowy/2)
print (xa, ya)
while cntcnt<times:
temp1 = Image.open("/Users/evrozm/Desktop/browserStack/{}icon.png".format(games[cntcnt]))
temp1Gray = temp1.convert('L')
temp1GrayNp = np.asarray(temp1Gray)
resultdelete1 = match_template(ssfordeleteGrayNp, temp1GrayNp)
dij = np.unravel_index(np.argmax(resultdelete1), resultdelete1.shape)
sizeoftemp1y=temp1GrayNp.shape[0]
sizeoftemp1x=temp1GrayNp.shape[1]
xd1, yd1 = dij[::-1]
xd1 = xd1 + (sizeoftemp1x/2)
yd1 = yd1 + (sizeoftemp1y/2)
print (xd1, yd1)
ActionChains(driver).move_by_offset(xd1,yd1).perform()
temp2 = Image.open("/Users/evrozm/Desktop/browserStack/delete.png")
temp2Gray = temp2.convert('L')
temp2GrayNp = np.asarray(temp2Gray)
resultdelete2 = match_template(ssfordeleteGrayNp, temp2GrayNp)
dij = np.unravel_index(np.argmax(resultdelete2), resultdelete2.shape)
xd2, yd2 = dij[::-1]
sizeoftemp2y=temp1GrayNp.shape[0]
sizeoftemp2x=temp1GrayNp.shape[1]
xd2, yd2 = dij[::-1]
xd2 = xd2 + (sizeoftemp2x/2)
yd2 = yd2 + (sizeoftemp2y/2)
print (xd2, yd2)
ActionChains(driver).move_by_offset(xd2,yd2).click().perform()
cntcnt = cntcnt+1
다음 : 기 가능성이 라인을 따라 http://selenium-python.readthedocs.io/api.html
뭔가 도움이 될 것입니다. 오프셋이있는 요소로 이동하는 대신 커서를 오프셋으로 직접 이동하려고합니다. 그래서 move_by_offset을 사용했습니다. 그러나, 당신의 도우미에 대한 고마움에 여전히 감사드립니다. – evrim