zoukankan      html  css  js  c++  java
  • selenium===splinter模块和selenium异曲同工

    顺便提一下

    如果有任何问题,你可以在这里找到我 ,软件测试交流qq群,209092584

    http://splinter.readthedocs.io/en/latest/

    安装以后用它来实现163邮箱的登陆操作:
    *和selenium一样,splinter同样需要对frame进行切换

    from splinter import Browser
    
    browser = Browser()
    browser.visit('https://mail.163.com')
    
    # 163的登录框在iframe中,所以无法使用dom查找,可以splinter提供的相关API
    
    with browser.get_iframe('x-URS-iframe') as iframe:
     iframe.find_by_name('email').fill('yourName')
     iframe.find_by_name('password').fill('yourPassWord')
     iframe.find_by_id('dologin').click()
     iframe.find_by_text('继续登录').click()
    
    if b.is_text_present('写信'):
        print('yes!')
    else:
        print("sorry!")

    browser.fill('email','xxxx')                #by_name        field = self.find_by_name(name).first

    关于查找元素的方法:

      Splinter provides 6 methods for finding elements in the page, one for each selector type: css, xpath, tag, name, id, value, text. Examples:

    browser.find_by_css('h1')
    browser.find_by_xpath('//h1')
    browser.find_by_tag('h1')
    browser.find_by_name('name')
    browser.find_by_text('Hello World!')
    browser.find_by_id('firstheader')
    browser.find_by_value('query')

    If you need to find the links in a page, you can use the methods find_link_by_text, find_link_by_partial_text, find_link_by_href or find_link_by_partial_href. Examples:

    links_found = browser.find_link_by_text('Link for Example.com') links_found = browser.find_link_by_partial_text('for Example') links_found = browser.find_link_by_href('http://example.com') links_found = browser.find_link_by_partial_href('example')

    详细参考:http://splinter.readthedocs.io/en/latest/finding.html

    表单切换:get_iframe(name)

    Changes the context for working with iframes.

    You can use the get_iframe method and the with statement to interact with iframes. You can pass the iframe’s name, id, or index to get_iframe.

    with browser.get_iframe('iframemodal') as iframe:
        iframe.do_stuff()


    #for example
    with browser.get_iframe('x-URS-iframe') as iframe:
     iframe.find_by_name('email').fill('yourName')
     iframe.find_by_text('继续登录').click()
  • 相关阅读:
    Oracle分页之一:最普通的分页方式
    MSSQL存储过程学习笔记一:关于存储过程
    MSSQL自动备份数据库
    小试JQuery的AutoComplete插件
    利用面向对象的方式来使用JS
    Oracle分页之三:利用PagerView来实现无刷新GridView
    由于 ASP.NET 进程标识对全局程序集缓存没有读权限,因此未能执行请求。错误: 0x80131902
    终端服务器超出最大允许连接数
    从苹果的Siri说起:云搜索与人工智能
    [转]为什么我们程序员难晋升
  • 原文地址:https://www.cnblogs.com/botoo/p/8328156.html
Copyright © 2011-2022 走看看