Test heart _Python Se_004 <manipulate text box object>

Tips: Code Description

  1. Environment Configuration: win10 + pycharm + python 3.6 + se 3.13
  2. Test requirements : Test baidu home page, search keywords, and return to the home page, click on the news link, enter the main page news
  3. Precautions:
    • se3, different browsers need to match different drive driver, and version compatibility
    • Case of driver drive configuration: under python installation environment directory: C: \ Python \ Python36-64 \ Script
    • Important to understand: script operational portion , generally test case 'Procedure ' corresponds

#coding: UTF-. 8 
from the webdriver Selenium Import
from Import Time SLEEP
"" "initialize the webdriver, understood as: a pre-operation" ""
FF = webdriver.Firefox ()
ff.maximize_window ()
ff.implicitly_wait (. 3)
ff.get ( "https://www.baidu.com")
"" "
test requirements: keyword search, and return to the home page, click on the news link into the main page news
ways: through different positioning way, find the page elements, and the operation elements, understood as: a user operation, operational
"" "
input_ele = ff.find_element (by =" name ", value =" WD ") is positioned to by name attribute #: input box
btn_ele = ff.find_element (by =" id ", value =" su ") # targeting by id attribute: button

input_ele.clear () # analog: empty contents of the operation input box
input_ele.send_keys (" china 2019 ") # analog: operation contents input from the keyboard
print (input_ele. get_attribute ( "value")) # acquires the element tag 'value attribute 'value: China 2019
btn_ele.click () Analog #: click, Submit button operation
print (ff.current_url) # get the page url address click the button operation

back to the Baidu home page ff.back () #
the NEWS_LINK = ff.find_element_by_link_text ( "News") # Positioning via text: hyperlinks
print (news_link.text ) # get hyperlink elements: text content
news_link.click () # click on the hyperlink

"" "expected results compare with the actual results of the assertion" ""
Print (ff.current_url) # url address current output, for debugging
assert " news "in ff.current_url," error prompt "

" "" exit driver to close the browser, understood as: post-condition "" "
ff.quit ()

Guess you like

Origin www.cnblogs.com/xqsxtest/p/11096179.html