Selenium one of the page interactions: Webdriver Browser Properties

Source: Internet
Author: User

Selenium provides many API methods to interact with the page, such as click, keyboard input, turn off Web pages, enter text, and more.

Webdriver provides many properties to the browser to operate the browser, commonly used

Get (URL), quit () Maximize_window () Current_url

Back () forward () Current_window_handle and window_handles

To open Baidu Home-----Point of registration, to register also registered------then go to the login page login as an example explanation

The specific code is as follows:

#coding =utf-8
Import Time
From Selenium import Webdriver

Driver=webdriver. Firefox ()
Driver.maximize_window ()
driver.implicitly_wait (+)
driver.get (' https://www.baidu.com/')
driver.find_element_by_partial_link_text (U ' login '). Click ()
dlwindow=driver.current_window_handle# The handle to the login window
driver.find_element_by_link_text (U ' Register Now '). Click ()
windows=driver.window_handles# handle of all Windows
For item in Windows:
if Item!=dlwindow:
Driver.switch_to_window (item) #如果item不是登录那个窗口的句柄 (that is, the handle to the registration window), Driver swithto the registration window
#注册
driver.find_element_by_id (' Tangram__psp_3__username '). Send_keys (' Pandaa ')
driver. find_element_by_id (' Tangram__psp_3__phone '). Send_keys (' 18298888888 ')
Time.sleep (3)
#去登录页面用新注册的账号登录百度
Driver.switch_to_window (Dlwindow)
driver.find_element_by_id (' Tangram__psp_10__username '). Send_keys (' Pandaa ')
driver.find_element_by_id (' Tangram__psp_10__password '). Send_keys (' ****** ')
driver.quit ()

Forward () back ()

Open Baidu---Point news to the news page---back, home----point
forward, to the news page
The code is as follows:
#coding =utf-8
Import Time
From Selenium import Webdriver

Driver=webdriver. Firefox ()
Driver.maximize_window ()
driver.implicitly_wait (+)
driver.get (' https://www.baidu.com/')
driver.find_element_by_partial_link_text (U ' News '). Click ()
Driver.back ()
Time.sleep (3)
Driver.forward ()
Time.sleep (3)
driver.quit ()

Selenium one of the page interactions: Webdriver Browser Properties

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.