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

在做移动端页面自动化测试时,遇到了一个用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)
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值