Python+selenium Browser Back forward operation + Get current page title+ get current page URL

Source: Internet
Author: User

#coding =utf-8 from    Selenium import webdriver  import time   driver = Webdriver. Chrome ()  Driver.maximize_window ()  driver.implicitly_wait (6)    driver.get ("https://www.baidu.com")  driver.find_element_by_id ("kw"). Send_keys ("Selenium") driver.find_element_by_id ("su"). Click () time.sleep (3) Driver.back () time.sleep (3) Driver.forward () Time.sleep (3) ele_string = Driver.find_element_by_xpath ("//*[@id = ' 1 ']/ H3/a/em "). Text  if (ele_string = =" Selenium "):  print U" Test succeeded, the result matches the expected result! " "Print (driver.capabilities[' version ')") Driver.find_element_by_xpath ("//*[@id = ' S_tab ']/a[text () = ' News ']"). Click () # On the Search results page, click on the News category  Time.sleep (1)  print (Driver.current_url)  # Current_url method to get the URL of the current page  print ( Driver.title)  # Title method can get the title of the current page to display the field  driver.quit ()

  

Python+selenium Browser Back forward operation + Get current page title+ get current page URL

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.