There is sth wrong with input on my Ubuntu. So the first blog would is written in 中文版 about what I am doing during this weekend. I study python for a while the about Algorith and the network and now find some small project for practice. One of Pratice is to log on website automatically. Splinter is an interesting item which would cover web communication and testing. Following link is a implementation on what to log on 12306 to buy ticket presented by Youerning. http://youerning.blog.51cto.com/10
0. Import keyboard class keys ()
The keys () class in Selenium provides most of the keyboard manipulation methods, and the Send_keys () method is used to simulate keys on the keyboard.# 导入键盘类 Keys()from selenium.webdriver.common.keys import Keys
1. Common keyboard operation:
Send_keys (keys.back_space): Delete key (BackSpace)
Send_keys (Keys.space): SPACEBAR (space)
Send_keys (keys.tab): Tab key (TAB)
Send_keys (Keys
element_located_to_be_selected# determines whether the selected state of the element is the same as expected, passed in parameters: the positioned element, equal returns TRUE, otherwise returns falseelement_selection_state _to_be# determines whether the selected state of an element is the same as expected, passed in parameters: element positioning, equality returns TRUE, otherwise falseelement_located_selection_state_to_be# determines whether an element is still in the DOM, Passing in the Webel
Selenium official websitehttp://selenium-python.readthedocs.io/Configuring the Usage environmentDownload the appropriate browser driver, Firefox is the defaultThis article is based on Chrome, placed in the scripts directoryChromedriver official: All versions of ChromedriverDocument referenceA Concise Python tutorialPython Tutorial-LiaocheOfficial document: Selenium
. -element: Positioned elements If the parameter is not written is the current position of the mouse for example, press CTRL + C:: Actionchains (Driver). Key_down (Keys.control). Send_keys (' C '). KEY_UP (Keys.control). Perform ()DefKey_up(Self, value, Element=none):# Release the keys to use with the aboveDefMove_by_offset(Self, Xoffset, yoffset): The offset that moves the mouse to the current mouse position-the xoffset:x axis moves to the X offset-yoffset:y axis offset as a positive or negativ
parameter is not written, then is the current mouse position-if the parameter is written to the element object, it is this element. def send_keys (self, *keys_to_send): The key to send to the current focus element. Modifier-Keys constants can be used in the button class. def send_keys_to_element (self, element, *keys_to_send): Sent to the anchored element-element: Positioned elements-keys_to_send: The key to be sent. Modifier-Keys constants can be used in the button class.Source code can
1.selenium Installation:Pip Install-u SeleniumReference: Https://pypi.python.org/pypi/selenium#downloads2. Download the Firefox driver:Https://github.com/mozilla/geckodriver/releases3. Configure the directory where the Geckodriver.exe is located to the PATH environment variable4. A simple example:1 from Import Webdriver 2 3 driver=webdriver. Firefox ()45 driver.get ("http://www.sogou.com") # The end of the
python + Selenium automation environment Frequently Asked Questions summary (1) There are three ways to operate the Windows window, one is to use the AutoIT software to generate exe programs, and then use the system command calls; SendKeys class simulates the keyboard operation (only the current focus is fixed); Pywinauto Components ( Win32gui )(2) Pywinauto package only supports to python2.6 version. the
Jenkins+selenium can achieve continuous integration of web automation.
The basic operation of Jenkins:
First, new view and job
New View:
New job:
You can choose to build a free-style software project or copy an existing item
Ii. Preparatory work:
Install Jenkins plugin, SSH plugin, Email Extension plugin, Hudson SELENIUMHQ plugin
Click System Management, manage plugins
Enter the plugin name in
When using selenium to automate, one of the headaches that we often encounter is file uploads.The difficulty of the problem is that selenium cannot recognize and manipulate the Windows window, and if we can bypass the popup box and pass the file information directly to the selection button, the difficulty is solved.the following are common page forms :parsing HTML, found that both the normal foreground and
1. Download the imageThe link is best, and almost all possible methods are enumerated, except that it does not mention the use of urldownloadtofile, but it is similar to WebClient.https://stackoverflow.com/questions/18424624/using-selenium-to-save-images-from-page/488712832. Full Exit SeleniumIn general, you can use Webdriver's Quit method. But in some cases, it may be useless. At this point, we can only kill the process.Interestingly, the way Iewebdr
with the elements before the refresh to locate the click, Nature will error.Second, the solution1. For the page refresh, the previous element failure problem, in the For loop body can be repositioned once, overwriting the old before the line.2. After the first acquisition of all elements, the total number is obtained through the Len function3.for loop do not loop positioning elements of the list object, replaced by a range function to cycle4. The reference code is as follows:```# Coding:utf-8Fr
Problems occurred1. Launch browser with Selenium ' chrome is under control of automatic software '2. If you do not want to see this annoying hint, start the browser by adding a configuration on the lineDisable-infobars1. In the browser configuration add a parameter, ignore this warning prompt
option = Webdriver. Chromeoptions ()Option.add_argument (' Disable-infobars ')
Reference Code # Coding:utf-8 from
Selenium Web Automation-how to find elements2016-07-291. What is an element?Element: http://www.w3school.com.cn/html/html_elements.asp2. Positioning method AnalysisSelenium Webdriver provides an advanced technology to locate Web page elements. The Selenium feature-rich API provides multiple targeting strategies such as Name, ID, CSS selector, XPath, and so on, as
positioning of the page, and the method encapsulated by the business operation code associated with those elements.4. Code reuse, which reduces the amount of test script code.5. Clear hierarchy, while supporting the development of multiple writing automation scripts, such as how many pages each person writes, does not affect others.6. It is recommended that both the page class and the business logic approach give a meaningful name to make it easy for
true testing class11 @FindBy (xpath= "//input[contains (@data-value, ' sort ')]")22privatewebelement XPath;33privatewebelement ID;44Publicpage () {55 CO =NewCom ();66 pagefactory.initelements (Driver, This);77 }88publicvoid XPath () {99 This. Xpath.click;Ten10 } One11publicvoid ID () { A12 This. Id.click; -13}So our original script could be changed to1 page page=new page (); 2 page.id (); 3 Page.xpath ();After the change, our script looks a lot simpler, and the development of the UI, we just m
1. Install python,:http://python.org---installation version 3.5.1PS: Comes with Setuptools and PIP tools2. Then, pip install the third-party libraries needed to develop the Web App: Asynchronous framework Aiohttp:$pip install aiohttp3. front-end template engine jinja2:$ pip install jinja24, MySQL 5.x database, download and install from the official website, after installation, it is important to remember the root password---test2345. MySQL python asynchronous driver Aiomysql:$ pip install aiomys
to process XML files, so it should be introduced First.Parse ()Xml.dom.minidom.parse () is used to open an XML file and will be the DOM variable for this file Object.DocumentElementDocumentElement is used to get the document elements of the DOM object and to give the obtained object to rootEach node has its nodename,nodevalue,nodetype Property. NodeName is the node Name.NodeValue is the value of the node and is valid only for text Nodes.NodeType is the type of Node.Getelementbytagname () can ge
1. Multi-Window switchingBrowser.window_handles Show All HandlesBrowser.current_window_handle Show Current handleBrowser.switch_to_window (browser.window_handles[1]) toggle Handle2. JS dialog box processingalter = Browser.find_element_by_xpath ('//*[@id = "Topguideloginform"]/div[4]/button '). Click ()Switch_to_alert () cut to alter returns an Alter objectAlter.accept () ConfirmAlter.dismiss () CancelSend_keys () have input box to use, otherwise error#coding =utf-8 from
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.