selenium===splinter模块和selenium异曲同工

学习文档:

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()

 

转载于:https://www.cnblogs.com/botoo/p/8328156.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值