7

Java webdriver の約 100 のタッチ イベントの例をオンラインで見ましたが、Python のタッチ イベントは 1 つもありません。何時間もの検索時間を節約できるように、誰かが親切にもここに投稿してくれませんか? これは、Androidシミュレーターの要素を拡大するために、基本的なdouble_tapを実行しようとする私の試みです。どうもありがとう

編集: ジュリアンの助けのおかげで、欠落しているリンクを見つけることができました: 何らかの理由で、タッチ アクションには最後に追加の.perform()が必要です。以下に、アクション中の一連のタッチ イベントを示します。コードはより簡潔になっています。楽しみ!

import unittest, time
from selenium import webdriver

print "Here are our available touch actions (ignore the ones that look like __xx__): ", dir(webdriver.TouchActions)
#print dir(webdriver)



class Test(unittest.TestCase):


    def setUp(self):
        self.driver = webdriver.Remote(command_executor='http://localhost:8080/wd/hub',  desired_capabilities=webdriver.DesiredCapabilities.ANDROID)
        self.touch =webdriver.TouchActions(self.driver)

        #self.driver = TouchActions(self.driver)
        #self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)


    def testHotmail(self):
        self.driver.get("http://www.hotmail.com")

        elem=self.driver.find_element_by_css_selector("input[name='login']")
        #tap command
        self.touch.tap(elem).perform()
        time.sleep(2)
        elem.send_keys("hello world")
        time.sleep(2)
        #double tap
        self.touch.double_tap(elem).perform()
        time.sleep(2)

        #testing that regular webdriver commands still work
        print self.driver.find_element_by_partial_link_text("Can't access").text

        elem= self.driver.find_element_by_css_selector("input[type='submit']")
        self.touch.tap(elem).perform()
        time.sleep(3)




    def tearDown(self):

        time.sleep(3)

        try:
            self.driver.quit()
        except Exception:
            print(" TearDown Method: Browser seems already closed.")

        pass


if __name__ == "__main__":
    unittest.main()

元の Java の例を次に示します。

WebElement toFlick = driver.findElement(By.id("image"));
// 400 pixels left at normal speed
Action flick = getBuilder(driver).flick(toFlick, 0, -400, FlickAction.SPEED_NORMAL)
        .build();
flick.perform();
WebElement secondImage = driver.findElement(“secondImage”);
assertTrue(secondImage.isDisplayed());
4

2 に答える 2

5

私はあなたの例にいくつかの調整を加えました.少なくともテストはエラーなしで実行されます. ユーザーがユーザー名フィールドをダブルタップしたときに Web サイトが何をすることを期待しているのかわかりません...

改訂されたコードは次のとおりです。

import unittest, time

from selenium.webdriver import Remote
from selenium.webdriver import  DesiredCapabilities
from selenium.webdriver.remote import webelement , command
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.touch_actions import TouchActions




class Test(unittest.TestCase):


    def setUp(self):
        remote = Remote(command_executor='http://localhost:8080/wd/hub',  desired_capabilities=DesiredCapabilities.ANDROID)
        self.remote=remote
        remote.implicitly_wait(30)

    def tearDown(self):
        pass


    def testName(self):
        # self.remote.get("http://icd.intraxinc.com/pxr")
        self.remote.get("https://icd.intraxinc.com/pxr/ext/login.action")
        elems= self.remote.find_element_by_css_selector("#j_username")
        print dir(self)
        print dir(self.remote)
        touchactions = TouchActions(self.remote)
        print dir(touchactions)
        touchactions.double_tap(elems)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()

直面している問題をどのように調査したかを示すために、例にさまざまな debug print ステートメントを残しました。また、URL をログイン ページのリダイレクト先に変更しました。これは、デバイスにインストールされている Android ドライバーのバージョンで発生した無関係な問題の回避策でした。

参考までに: Android 4.0.4 を実行している Android フォンで android-server-2.21.0.apk をテストしました。サンプルコードへの重大な変更は次のとおりです

        touchactions = TouchActions(self.remote)
        print dir(touchactions)
        touchactions.double_tap(elems)
于 2013-04-11T19:36:14.847 に答える