private methods essentially correspond to the single-element positioning and multi-element positioning described above. 8 class method, as follows:From selenium.webdriver.common.by Import byDriver.find_element (By.xpath, '//button[text () = "Some text"])Driver.find_elements (By.xpath, '//button ') by Properties available for the classID = "id" XPath = "XPath"
One of the most important things about selenium automated testing is the element positioning, which cannot be manipulated if the element is not positioned, and it is impossible to automate the test. Online for the element positioning has a lot of introduction, very detailed and detailed, but still have a lot of novice
Drag and drop, the use of the mouse to implement the drag-and-drop operation seems very complex, in Selenium, with the help of OpenQA.Selenium.Interactions.Actions class Library provides methods, the implementation is relatively simple. The rationale is as follows:1. Locate the page element you want to drag-source.2. Find
Selenium Webdriver Learning (10)------------How to drag and drop an element into another elementBlog Category:
Selenium-webdriver
Element drag and drop drag and dropQ Group Sometimes people ask, selenium webdriver How to implement an
"]
*
Wildcard characters, matching all
Example: Positioning the Baidu input box, according to the attribute Name= "WD" (You can press CTRL + F in the Google Chrome debugging tool to open the positioning input box)4. XPath positioning and functions and logic
Functions and logic
Describe
Example
Text ()
The text content of the element
*[@id = "xxx"]//p[text () = "XXXX"]
development of testability, add unique ID, name and so on.
7. If you cannot find a unique location, look for all of its child nodes (look at ID, name, text, title) until it finds a unique one.
Then use its child node XPath to uniquely locate its XPath similar to the following:
input[@id = ' main ']/parent::xxx 8. If you can't locate it yet, look for all of its sibling nodes (look at the ID, name, text, title), and index itself in the sibling node unt
1. Using Thread.Sleep (), this is the most stupid method, but sometimes it can be used and very useful.2. Implicit wait, implicit wait is when you want to find the element, and this element does not appear immediately, tell Webdriver to query the DOM for a certain time. The default value is 0, but after the setting, the time will work for the entire life cycle of
. The above positioning method is positioned by a property of the element, if an element does not have an ID, name, class attribute, or hyperlink, do it? Or it's a lot of properties that are duplicated. At this point, you can use XPath to solve2.xpath is a path language, with the above positioning principle is not the same, first first step to learn to use the to
1.Webdriver principleWebdirver is a Web automation tool that provides a unified Webdriver interface to the browser, which is submitted by client, our test script, and the remote server browser responds to the request. Compared to the original selenium1 in the Selenium RC is more convenient, the browser operation more flexible.2. Positioning(1) Positioning of elements:The positioning of the elements can be achieved by Id,name,
Selenium is a tool for automated testing and can be used in Python for automated testing.Selenium can be superficially understood as: a Web page that simulates a person's various actions, such as clicking a button, entering information, and so on. Let's talk today about how to locate the button we want to click, or the Information box to enter the information.---------------------------------------------------------------------------------------------
("//div/input[@value = ' query ']");Practical Examples:Query the second input,xpath is starting from 1Driver.findelement (By.xpath ("//input[2]"));Position the first picture of the pageDriver.findelement (By.xpath ("//img[@href = ' xxx ')");Position the first input input box in the second DivDriver.findelement (By.xpath ("(//div[@class = ' mob-share-list ')" [2]/input[1] "));Fuzzy positioning: Start-withLook for the A
element in a direct child element of a form, with no spaces before the colonCan be anchored to an element: 4) Last child element : Last-child [similar: First-child]Webelement userName = Driver.findeleme (By.cssselector ("Form:last-child"));//A colon preceded by a space, positioned to the first child of all levels unde
Positioning element MethodsWebsite address: http://selenium-python.readthedocs.org/locating-elements.htmlHere are a variety of strategies for locating elements in a Web page (locate elements), you can choose the most appropriate scenario, selenium provides a way to define the elements of a page:
find_element_by_id
Find_element_by_name
Find_elemen
Java Selenium processing elements in an IFRAME
Sometimes when we locate elements, we find that we cannot locate them. You need to check to see if the element you're targeting is in the IFRAME.
Reading Table of Contents
What is an IFRAME?
An IFRAME is HTML, used for Web page nesting. A Web page can be nested into another page and can be nested in many layers.
First, the solution of ideasOur general approach is to sleep time and to wait for an element to appear and then perform the related actions we need. But both of these approaches have obvious drawbacks.The first way to sleep fixed time, the disadvantage is: 1. Waste time, sometimes the element is loaded OK, but still have to wait for sleep time to finish before execution; 2. Unstable, more difficult to weigh
Web page automation testing, the elements on the page positioning and operation is the core. And the operation is the premise of positioning, therefore, the positioning of page elements is the basis for automated testing.
The elements on the page, like people, have various attributes, such as element names, element IDs, element attributes (
This article describes how we use selenium to manipulate various page elements
Reading Table of Contents
Links (Link)
Input Box textbox
Buttons (Button)
Drop-down selection box (select)
Radio buttons (Radio button)
Multi-marquee check box
Links (Link)
Linked actions
Find link element
webelement link1 = driver
(Driver.findelement (by.id ("Proadditem_kind")); Select the corresponding selection, index starting from 0 Select.selectbyindex (2); Select.selectbyvalue ("+"); Select.selectbyvisibletext ("kind AA"); Get all the options listRadio buttons (Radio button) Actions for single-option elements Find the Radio box element String xpath= "//input[@type = ' R
the action to get the page element, click the button, and enter the form.the Selenium offers 8 positioning methods:
Id
Name
Class name
Tag name
Link text
Partial link text
Xpath
CSS Selector
here are the 8 ways to locate in the code:
Findelement (By.id ())
Findelement (By.name ())
Findelement (By.classna
Many tests fail because clicking on an element fails or entering text in a field that is not visible, or entering text in a text that cannot be entered.We can check the status of the elements before we do the actual operation. The Webelement class provides such a method.
Method
Objective
IsEnabled ()
Checks whether the element
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.