Uniquefu Python+selenium Learning--Print the title and URL of the current page

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.