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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM