())
Positioning elements with CSS selectors
by XPath
Driver.findelement (By.xpath ())
Driver.findelementS(By.xpath ())
Positioning elements through XPath
Findelement:1. By IDUsing the Id,name,class property is the preferred method for locating elements. Where the ID of the element is the most preferred method, is the fastest strategy.The id attribute cannot be us
= driver.findelement (By.id ("Father")). Findelement (Bylinktext ("xxx"));4. NosuchelementfoundexceptionThe Findelement () and findelements () methods throw the exception when the corresponding element is not found.Findelements:Selenium Webdriver's Findelements () method allows you to get a collection of specified rules for situations where you need to operate on a similar set of elements.Example: Verify the number of Baidu home navigation links and
corresponding column can be taken out as neededThe basic code is as follows:All_data=browser.find_elements (By.xpath,"//label[@class = ' current ']")#Select all date element pairs likeRowall=[rowall.text forRowallinchAll_data]#take out the corresponding date elementrowindex=[rowall.index (i) forIinchRowallifU'Saturday' inchI#Get column" "determine if Saturday can be scheduled, no 2s refresh" " whileTrue:td
Tags: com automation [] Win tools time code interface positioningThis article on the XPath method is the same as the previous CSS method, before using, you need to master some of the XPath knowledge. Of course, there are various tools on the web that can help us get to the XPath of the element, but it doesn't mean that we don't have to know about XPath, after all, the Reliance tool never relies on its own. But I will also introduce the XPath of the
Today, when you run an Automation use case, you find that an element always hints at not clickable. The reason for the analysis is probably the big top icon in the bottom right corner of the page, just blocking the element I want to click. To solve it, you have to pull the page, you need to manipulate the scroll bar on the page.A relatively simple method is used,
Use the following example to write a test scriptPage code:link href= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"rel= "stylesheet"/>script src= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js" >class= "Well" > class= "Form-horizontal" > class= "Control-group" > class= "Control-lable" for=
The test page contains display:none elements, so consider using JS, in the process of using JS, JS to get the object of the page, no ID, no Name......a class= "Employer" href= "javascript:;" > XXX1i class= "icon-arrow icon-arrow-down">i> a> div class= "dropdown-menu" style= "display:none;" > dl> dd> a target= "_blank" href= "/xxx"> release a>
Python3 selenium randomly selects an element of the same type, python3selenium
Use Cases:
As shown in, sometimes, when we test, we do not select every direction, nor can we select one direction each time. At this time, we need to run the case each time, randomly select a direction for testing
Usage:
random.randint()
Example:
1 #_. _ coding: UTF-8 _. _ 2 3 "" 4: author: Flower Test 5: time: 2017.05.04 6:
Many examples on the internet, but the last time you send the message when the element not visible error, because the page has two send buttons, after several twists and ends, finally finished.
Package Selenium_java;
Import java.util.List;
Import Org.openqa.selenium.By;Import Org.openqa.selenium.WebDriver;Import org.openqa.selenium.WebElement;Import Org.openqa.selenium.chrome.ChromeDriver;Import org.openqa.selenium.interactions.Actions;
public
First, for uploading files, from the manual operation we can see that the window form needs to operate, and for the selenium webdriver in this area of application is limited. However, fortunately, for the upload containing the input element, we can pass the file path directly through the SendKeys, omitting the operation of the window form to implement the file upload, the implementation process is as follow
(). window (). Maximize (); Driver.get ("Https://www.baidu.com"); //by LinkText Find elementsDriver.findelement (By.linktext ("News")) . Click (); Thread.Sleep (1000);Back to Baidu homepageDriver.navigate (). back ();Thread.Sleep (1000); //by Partiallinktext Find elementsDriver.findelement (By.partiallinktext ("Set as Home") . Click (); }}The Thread.Sleep () that appears in the code is the meaning o
The previous article is the positioning of elements, then the purpose of positioning elements is to manipulate elements, such as writing text, click Buttons, drag and so on operations(1) Simple element operationSimple element manipulationfind_element_by_id ("kw"). Clear () #文本框清空 find_element_by_id ("kw"). Send_keys ("selenium")
Preface: wrote a script before, want in the IP site inquires over more than 1000 domain name the record information, but some domain name is not the record, therefore cannot find the element, although I already set the unusual judgment, but the default waiting 30 seconds time let me unbearable. Then after a variety of Baidu found a solution.
Digression: A colleague uses Nodejs to solve more than 1000 data
]")); Emailimgvcode.click (); WaitTime (3000); //Get the Password check information node and determine when it exists and whether the information is "Password strength: High"Webelement Checkpassword = driver.findelement (By.cssselector ("[Class=password3]")); if(Checkpassword.isdisplayed () "Password strength: High". Equals (Checkpassword.gettext ())) { //after the password check is passed, get the authentication verificatio
Error found when using class to locate elements:Error message: Selenium.common.exceptions.InvalidSelectorException:Message:Compound class names not permitted (the name of the composite class is not allowed)Online inquiry information learned:ClassName does not allow the use of compound class names for parameter "origina
Sizzle CSS3 also provides some pseudo-classes that directly select form elements
:input: Finds All input elements (includes Textareas, selects, and buttons).
:text,,,,,,, :checkbox :file :password :submit :image :reset , :button : Finds the INPUT element with the specified input type (: Button also fin DS button elements).
Here are some synonyms for XPath and CSS locator comparison
Positioning method
Xpath
Css
Software Test Exchange QQ Group: 631646987, look forward to your joining!!Ideas:
Referencing the jquery class library
Change element properties with jquery code
Now to change the Baidu page attributes for example, delete the id attribute, Baidu input box and button background color changed to redThe code is as follows: Packagecom.webdirver.test;Importorg.apache.commons.lang3.StringUtils;Im
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.