2017-11-27 12 views
1

私はBrowserChackで使用する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、YA).click()(実行)

the page I am working in

コード:

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 

答えて

0

私はPythonでうまくいきませんが、私は次のdocumentaのセクション7.2(Action Chain)を願っていますmove_to_element_with_offset(to_element、XOFFSET、YOFFSET)私はそのリンク内の情報を使用し、クリック

+0

続く:ションは、おそらく、これらの線に沿ってhttp://selenium-python.readthedocs.io/api.html

何かをするのに役立ちます。オフセットのある要素に移動する代わりに、カーソルをオフセットに直接移動したいと思っています。なぜ私はmove_by_offsetを使用したのですか?しかし、私はまだあなたの助けを借りて感謝しています。 – evrim

関連する問題