The following is a simple example Import Time fromSeleniumImportWebdriver fromSelenium.webdriver.common.keysImportKeysbrowser=Webdriver. Chrome () Browser.get ("http://www.python.org")assert "Python" inchBrowser.titleelem= Browser.find_element_by_name ("Q") Elem.send_keys ("Pycon") Elem.send_keys (Keys.return)assert "No results found." not inchBrowser.page_sourcetime.sleep (20) Browser.close ()Analyze the instanceThe Selenium.webdriver module provide
---restore content starts---environment construction under WINDOW101. Install Pythonhttps://www.python.org/downloads/Download the latest version of Python under this URL, click Install, select Add Python path to PATH environment variable during installation2. Installing Setuptools and PipSetuptools makes it easier to create and publish Python packages, especially
"Python automation Selenium+appium" starts August 11! (2 months 2000, package Church) lecturer: Shanghai-leisurely class way: QQ group video online teaching registration fee 20,001 people (cycle 2 months) Contact qq:283340479 Personal Achievements:1. Personal blog, Baidu Direct search: Shanghai-Leisurely blog2. Personal original public number: Yoyoketang3. Already in Baidu read on-line book, Baidu Search: B
, literally can imagine some of these framework background and components, this article just have a basic understanding of the framework.3. Framework Basic ComponentsLet's consider the following framework components:1) requires profile management2) Separation of business logic code and test scripts3) Report and log file output4) Packaging of custom libraries5) Manage and Execute script mode6) Introduction of third-party plugins7) Continuous IntegrationExplain:We need a configuration file to cont
From selenium import WebdriverImport timeBrowser = Webdriver. Firefox ()Browser.get (' www.baidu.com ')I do the test when my web page needs to open Firefox while opening its plug-in, and this way to open a Firefox without any plug-in, which gives me a lot of trouble with the test, I looked on the internet, it is said to use the following method can open a plug-in, That is, usually you turn on the computer interface which Firefox, so we try to see: The
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_element_by_xpath
Find_element_by_link_text
This article reproduced: http://blog.csdn.net/u011541946/article/details/70141488Http://www.cnblogs.com/timsheng/archive/2012/09/05/2672651.htmlIt is necessary to introduce how to use the Selenium method in the testing process, especially when encountering errors. There are three main methods in selenium for Python, and we pick one of the most common ones.Skills
positioned to the ID of the element, can be implemented by the following code. Js= "var q=document.getelementbyid (' id '). scrolltop=10000" Driver.execute_script (JS) 1.2, scene two There are scroll bar of the page everywhere, this is easier to find examples, we operate Baidu search results page for example: #coding =utf-8from Selenium Import webdriverimport time# visit Baidu Driver=webdriver. Firefox () driver.get ("http://www.baidu.com") #搜索dr
positioning function is different,The first uses the name , the second type of CSS. How to remove the tick:There is also a problem, sometimes we do not want to tick all the page check box (checkbox), you can use the following method to remove the last tick box. As follows:#-*-Coding:utf-8-*-From seleniumImportWebdriverImportTimeImportOSDR =Webdriver. Firefox () File_path =‘file:///' + Os.path.abspath (‘Checkbox.html ") dr.get (file_path) # input[type=checkbox]" ) for checkbox in Checkboxes:chec
Sometimes you need to execute a JS script on the page when you are automating the test.Execute_script method.From selenium import WebdriverBrowserobj_dirver = Webdriver. Ie ()Browserobj_dirver.get ("http://www.soso.com")Browserobj_dirver.implicitly_wait (5)Browserobj_dirver.execute_script ("q = document.getelementbyidx_x_x (' TB ');" + "Q.style.border = ' 1px solid red ';")The above code opens the first page of the Soso and highlights the DIV with the
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-8from sel
system environment variable to add the path of chrome to the path (as in the steps).5. Open the IDE (such as Pycharm) to write the code, and test it with the following code:6. Run the 5th step of the code, it is very likely to error, given a similar to Chromedriver.exe ..... path and other words of the wrong message .... How to solve it?
Close all open chrome browsers and run again.
If you close the Chrome browser, not yet, will also give an error, then restart the computer, it s
, powerful Chrome browser can automatically help you to generate elements of XPath, CSS and other properties. Take Baidu Home Source example, in the page source files, positioning to the element, right-click, the effect is as follows:Generated code after the copy, for this scenario can be directly used, but in view of the current page update is very frequent, it is recommended to simply learn under the selector of XPath, CSS, and other important methods, so we can write very flexible code, the p
a contentTitle_contains Title contains a contentPresence_of_all_elements_located y element is loaded, passed in the locating tuple, as (by.id, ' P ')visibility_of element visible, incoming locator tupleText_to_be_present_in_element an element literal contains a literalText_to_be_present_in_element_value An element value contains a fileElement_to_be_clickable an element can be clickedWait a minute6 Browser forward and backwardBrowser.forward ()Browser.back ()7CookiesCookies can be viewed, added
A good starting point for learning UnitTest is to record the export script from the selenium IDE. I believe many novice learning selenium also started from IED.
Using an IED to record a script
Export the script, save it as baidu.py, and open it through the Python idle editor. As follows:
From selenium import We
Article 7 python Automated test application-selenium Advanced article--lamecho1.1 OverviewHello everyone! I am lamecho (spicy ugly), this article will be our introduction selenium use of the last advanced article, will bring you some dry food to help everyone can deal with the actual problems encountered in the real combat.1.2
')) 3.3 Execute second.py, open the Command Prompt window, enter the directory where the second.py file is located, enter the command:p Ython second.py EnterNote: Here is to drive Firefox as an example, so need to install Firefox, if not installed can go to the Firefox official website to download the installation3.4 View Save the result file, go to the directory where the second.py file is located, find the XML file named Result-24. SummaryInstall selenium
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.