Turn: Selenium Webdriver+python basic operation

Source: Internet
Author: User

Turn from: http://blog.163.com/[email protected]/blog/static/1017337222013102310617946/

Import module:

From selenium import Webdriver

From selenium.common.exceptions import nosuchelementexception

Select browser: Driver = webdriver. Firefox ()

Open Url:driver.get ("http://www.baidu.com")

Wait: driver.implicitly_wait (30)

Driver.set_page_load_timeout (30)

Driver.set_script_timeout (30)

Close browser: Driver.quit ()/driver.close ()

Forward/Reverse: Driver.forward ()/driver.back ()

Refresh: Driver.refresh ()

Back to current page title: Driver.title

Return to current page Url:driver.current_url

Returns all windows of the current browser: driver.window_handles

Returns the window handle of the current browser: Driver.current_window_handle

Select window: Driver.switch_to_window ("Window_name")

dialog box action: Driver.switch_to_alert () #选择窗口对象

Accept () #点击确认

Dismiss () #点击取消

Text #获取文本值

Send_keys ("key") #输入值

Anchor Element (Single): Driver.find_element (by= "id", Value=none)

ID Locator: driver.find_element_by_id ("Id_name")

Name Locator: Driver.find_element_by_name ("name")

CSS positioning: driver.find_element_by_css_selector ("#foo")

XPath positioning: Driver.find_element_by_xpath ("//select[@id = ' nr ']/option[2]")

Link locator: Driver.find_element_by_link_text (U "link")

Tag locator: Driver.find_element_by_tag_name ("foo")

Intercept Current page: Driver.get_screenshot_as_file ('/screenshots/foo.png '

Other:

http://blog.163.com/[email protected]/blog/#m =0&t=1&c=fks_ 084068087080089070084083094095085086080068087085081065086

Turn: Selenium Webdriver+python basic operation

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.