Python 3.x 移动光标并单击Selenium WebDriver ActionChains

Python 3.x 移动光标并单击Selenium WebDriver ActionChains,python-3.x,image-processing,selenium-webdriver,Python 3.x,Image Processing,Selenium Webdriver,我一直在搜索要在BrowserStack中使用的ActionChain函数。 我想从Facebook上删除一个应用程序。在我使用它之后,我意识到不可能通过正常的selenium功能来查找元素并单击并删除应用程序,例如按id查找元素和按名称查找元素。所以,我决定使用一些图像处理。我在页面中查找应用程序的图标,并想在其上移动光标。然后出现X按钮。当它出现时,我想点击它。我已经找到了图标的位置,并使用ActionChain在上面移动了光标。但,光标停留在图标上的时间很短。ActionChain的点击功

我一直在搜索要在BrowserStack中使用的ActionChain函数。 我想从Facebook上删除一个应用程序。在我使用它之后,我意识到不可能通过正常的selenium功能来查找元素并单击并删除应用程序,例如按id查找元素和按名称查找元素。所以,我决定使用一些图像处理。我在页面中查找应用程序的图标,并想在其上移动光标。然后出现X按钮。当它出现时,我想点击它。我已经找到了图标的位置,并使用ActionChain在上面移动了光标。但,光标停留在图标上的时间很短。ActionChain的点击功能不起作用。我在下面添加了我的代码。如果您能帮助我了解ActionChain的这些移动光标和单击功能,我将非常高兴

图书馆:

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
ActionChainsdriver.move_by_offsetxa,ya.click.perform

代码:


我对Python不是很在行,但我希望下面文档的第7.2节操作链会有所帮助


可能是这样的:用偏移量移动到元素,xoffset,yoffset,然后单击

我使用了该链接中的信息。我不想移动到带有偏移量的元素,而是直接将光标移动到偏移量。这就是为什么我使用逐偏移移动。但是,我仍然感谢你的帮助。
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