使用python selenium TouchAction模拟实现lCalendar滚动和点击效果

本文介绍了如何在移动端自动化测试中,利用Selenium的TouchAction模拟用户操作,特别是针对使用Icalendar实现的地区选择框的滑动和点击。通过提供示例代码和TouchAction的方法说明,如double_tap、flick、scroll等,帮助读者理解如何在Python中执行这些操作。同时强调了在进行移动端测试时开启手机模拟器的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在做移动端页面自动化测试时,遇到了一个用Icanlendar实现的地区选择框。不同于PC所用的select,这个需要通过控制手指滑动的幅度来选择不同的地区。通过翻阅文档,我发现可以用selenium的TouchAction模拟用户在移动端的操作。TouchAction的文档地址:https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.touch_actions.html
示例代码:

def testWxLeaderSubmissionCreate():
    driver.get("http://10.0.11.129/index.php/mLeaderSubmission/create/leaderTaskId/1755/fUserId/22930")
    quotation = driver.find_element_by_name("LeaderSubmission[quotation]")
    quotation.send_keys("111")
    contact = driver.find_element_by_name("LeaderSubmission[contacts]")
    contact.send_keys("fanTest002")
    phone = driver.find_element_by_name("LeaderSubmission[phone]")
    phone.clear()#
    phone.send_keys("13699269673")
    description = driver.find_element_by_name("LeaderSubmission[description]")
    description.send_keys("页面自动化测试")
    #driver.execute_script('$(\"input[name=area_info]\").removeAttr(\"readonly\");')
    area_info = driver.find_element_by_name("area_info")
    area_info.click()
    time.sleep(2)
    action = webdriver.TouchActions(driver)

    #touch action参见:https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.touch_actions.html
    source = driver.find_elements_by_class_name('tooth')[1]
    print(source.text)
    action.scroll_from_element(source,0,100)#滚动ICalendar插件中的选项
    action.perform()
    time.sleep(3)
    action = webdriver.TouchActions(driver)
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值