Selenium Webdriver (3)

Source: Internet
Author: User

Mouse events:

Actionchains class
? Context_click () Right-click
? Double_click () Double-click
? Drag_and_drop () drag
right mouse button:

From selenium.webdriver.common.action_chains import Actionchains #导入ActionChains包

# Navigate to the element you want to right-click qqq=driver.find_element_by_xpath ("/html/body/div/div[2]/div[2]/ Div/div[3]/table/tbody/tr/td[2]# performs a right mouse button action on the anchored element Actionchains ( Driver). Context_click (QQQ). Perform ()"#你也可以使用三行的写法, but I think the above two lines are easier to understand chain = Actionchains ( Driver) Implement =driver.find_element_by_xpath ("/html/body/div/div[2]/div[2]/div/div[3]/table/tbody/tr/td[2]") Chain.context_click (Implement). Perform ()"

Other actions of the mouse:

# perform a mouse double-click on the anchored element actionchains (Driver). Double_click (QQQ). Perform () # performing a move operation on an element Actionchains (Driver). Drag_and_drop (element, target). Perform ()

To locate a group of elements:

 fromSeleniumImportWebdriverImport TimeImportOSDR=Webdriver. Firefox () File_path='file:///'+ Os.path.abspath ('checkbox.html') Dr.get (file_path)#Select all input on the page, then filter out all the checkboxes and tick theInputs = Dr.find_elements_by_tag_name ('input' ) forInputinchInputs:ifInput.get_attribute ('type') =='checkbox': Input.click () time.sleep (2) Dr.quit ()

Method Two:

#-*-coding:utf-8-*- fromSeleniumImportWebdriverImport TimeImportOSDR=Webdriver. Firefox () File_path='file:///'+ Os.path.abspath ('checkbox.html') Dr.get (file_path)#Select all the checkboxes and tick them all.checkboxes = Dr.find_elements_by_css_selector ('Input[type=checkbox]' ) forCheckBoxinchCheckboxes:checkbox.click () time.sleep (2)#Print the number of checkboxes on the current pagePrintLen (Dr.find_elements_by_css_selector ('Input[type=checkbox]')) Time.sleep (2) Dr.quit ()

# Remove the Dr.find_elements_by_css_selector ('input[type=checkbox]' from the last 1 checkboxes on the page   ). Pop (). Click () time.sleep (2)

Frame or window positioning:

Browser.switch_to_frame ("F1")# then find the ifrome2 below it (ID =f2) Browser.switch_to_frame ("f2")
#下面就可以正常的操作元素了
Driver.switch_to_window ("Windowname")

Selenium Webdriver (3)

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.