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