Scene
Test, access to 1 pages and then determine whether its title conforms to the expected is a very common 1 use cases, the so-called use case is not enough, title to come together is this truth. More specifically, assuming that the title of the 1 pages should be ' Hello World ', then you can write a use case: Access the page, get the title of the page, and determine if the value obtained equals ' Hello World '.
Getting the URL of the current page is also a very important operation. In some cases, when you access a URL, the system automatically jumps to that URL, which is called ' redirection '. The generic test redirection method is to access the URL, and then wait for the page to be redirected, get the URL of the current page, and determine if the URL is expected. Another common test scenario is to submit a form, and if the form content passes validation, it jumps to a new page, and if it does not pass validation, it stays on the current page, and getting the URL of the current page can help us determine if the form submitted jumps as expected. More specifically, if you test a landing page, enter the correct login information, will jump to the system homepage. It would be a good use case to get the URL after the jump and then determine if it matches the URL of the system's homepage.
Code
#!/usr/bin/env python#-*-coding:utf-8-*-"' Created on 2018/5/9 11:23@author:jeff lee@file: Title of current page and url.py ' from S Elenium Import webdriverimport timeprint (' Open browser ') CL = Webdriver. Firefox () time.sleep () url = ' http://58.251.136.209:19001/' Print (' open page ') cl.get (URL) time.sleep (3) Print (' current page ' title ', cl.title) print (' current page URL ', cl.current_url) print (' Close browser ') Cl.quit ()
Reference http://www.cnblogs.com/nbkhic/tag/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/
Uniquefu Python+selenium Learning--Print the title and URL of the current page