Discover selenium webdriver script example, include the articles, news, trends, analysis and practical advice about selenium webdriver script example on alibabacloud.com
(). Forward ();Wd.navigate (). back ();Hover Mouse:Hover the mouse may you think why you need this operation, I have been the example of the case, like this column under each model has multiple elements, want to find elements, this time need to simulate the mouse hover so that the hidden js Let us can find:Before hover:After hover:Instance:4. Set the wait Time:Force stop: ( 1son behalf of)Thread.Sleep(+);Global Wait: (unit:s)Wd.manage (). Timeouts (
Introduction
There are often children's shoes asking such questions:1. Where can i download chromedriver?2, why do I have a good chromedriver but Chrome won't start?Solution Solutions
Today we are going to solve them.1, chromedriver official website: http://chromedriver.storage.googleapis.com/index.htmlHere are all the versions, click on a version of the directory can see the detailed content, suffix Win32 is under Windows, suffix MAC64 is the Mac2, why do I have a good chromedriver but Chro
Selenium WebdriverFirst, locate a group of elements:Webdriver can conveniently use the Findelement method to locate objects that are fixed by a certain object. But sometimes we have to locate a group of objects, and then we need to use the findelements method.Application Scenarios:1. Bulk operation of objects, such as the selection of all the checkboxes on the page;2. First get a set of objects, and then filter out some objects that need to be located
driver.find_element_by_css_selector () above is a method of locating an element, The corresponding Webdriver also has a way of locating a set of elements: Driver.find_elements_by_name () driver.find_elements_by_id () driver.find_elements_by_ Class_name () Driver.find_elements_by_tag_name () Driver.find_elements_by_link_text () driver.find_elements_by_ Partial_link_text () Driver.find_elements_by_xpath () Driver.find_elements_by_css_selector () so the
http://blog.csdn.net/qingchunjun/article/details/42581261
When you use selenium webdriver for element positioning, you typically use the Findelement or Findelements method to position the element with the element handle returned by the by class. Among them, by the common positioning method of eight kinds, are described below respectively.
1. By.name ()
Page source code is as follows: [HTML] view plain c
During the implementation of automated testing, there are three steps to common page operations in the test program1. Locate the page elements on the page and store them in a variable2. Manipulate the page elements stored in the variable, click, drop down, or enter text, etc.3. Set the action value of the page element, for example, select the drop-down list in the drop-down list or enter what value in the input boxThe positioning of the page element i
:>>> ================================ RESTART ================================>>>[Name=key-aaaaaaa;path=/;Domain=www.youdao.com,VALUE=VALUE-BBBBBB;path=/;Domain=www.youdao.com]The last cookie information that can be seen from the printed result is added by the Addcookie () method during script execution. Through the TimesInformation to find the value of a specific cookie with key "name" and "value".Then under what circumstances will the operation of t
Sometimes in order to ensure the stability of the script run, you need to add the wait time in the script. Add hibernation
Import timeTime.sleep (0.3)Implicit wait
Set once, and after the element is not found, it will wait for 30s by default until the element is found. That is, there is a 30s waiting buffer to find the element. Driver.implicitly_wait (30) Explicit wait
Webdriverwait (). until () #10s内每隔5
Issues addressed in this verse:
How do I locate a set of elements?
Scene
As you can see from the example in the previous section, Webdriver can easily use the Findelement method to locate a particular object, but sometimes we need to locate a set of objects.
This is the time to use the Findelements method.
Locating a set of objects is generally used for the following scenarios:
Bulk manipulating objec
Linktext is the link text, we can find the element by LinktextFirst, the problem scenarioIn HTML the,As an example of a red box, an HREF represents a jump address after the link has been clicked, selenium to find the element by text informationSecond, the Code implementationThree, the realization principle1, first open the corresponding URL2. Navigate to the link by text message3. Click the link to open the
Refer to Http://www.cnblogs.com/tobecrazy/p/3599568.htmlWebdriver, you need to introduce:ImportJava.io.File;ImportJava.io.IOException;ImportOrg.apache.commons.io.FileUtils;ImportOrg.openqa.selenium.OutputType;Import Org.openqa.selenium.TakesScreenshot;Methodpublic static void Snapshot (Takesscreenshot drivername, String filename){This method would take the screen shot, require-parameters, one is driver name, and another is file nameString Currentpath = System.getproperty ("User.dir"); Get Curren
determine whether there is a Selenium official website this link.
7 exit the browser and end the test.
If you don't get the element's expression through the plugin Firepath on Firefox, see an article. If you don't have Chrome installed, use Firefox.
1 Desktop A new Notepad, named and saved as firstscript.py
2 Enter the following code fragment to firstscript.py, save
3 Open the cmd window, switch to the desktop path, and then execute the
system's environment variable path.For example, IE's driver file is IEDriverServer.exe. If you need a friend, go to the official website to download it.Second, write a simple linear script1. Principle of automatic testingAutomated testing, generally in three steps:1) Take the expected results;2) take actual results;3) Assert: Compare 1) and 2) to determine whether the test passed;2, simple selenium test
The previous section based on Python Selenium automated Testing (i)--element positioning describes the element positioning method, now we can write a simple automated test script applet to practice.
from Seleniumimport webdriver
Driver=webdriver. Chrome ()Driver.get ("http://www.baidu.com")driver.find_element_by_id ("
Selenium to get the JavaScript return value is very simple, just need to return the data in the JS script can be returned, and then through the method to return JS execution results, the method source code is as follows:1 /**2 * Get Object of return from JS3 * 4 * @authorAARON.FFP5 * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java execjsr, 2015-8-9 1:39:17 Exp $6
Install python (https://www.python.org/), download the latest Python version
Configure environment variables. (Example), I installed Python under/installation folder with Python 3.5.2. The path set is as follows:d:\installation\python3.5.2;d:\installation\python3.5.2\scripts;
Install Pip (you could search related steps from the Internet to install)(Locate To/scripts folder, to perform easy_install pip command650) this.width=650; "Title=" easy. JP
Now that the Web Automation environment has been set up, it's time to start writing scripts. Let's start with a relatively simple script, as follows:
#coding = Utf-8
From selenium import Webdriver
Import time
Try
Driver = Webdriver. Chrome ()
# driver =
1, selenium rc+eclipse download installationJava environmentOfficial website http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html, Java in this example SE1.8, installed in the D-disk JAVA folder, note the configuration of the environment variables: New variable java_home=d:\java\jdk1.8.0_11, add%java_ in the variable path Home%\bin;. Verify that Java is installed successfully: Ent
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:
[email protected]
and provide relevant evidence. A staff member will contact you within 5 working days.