object:
· Click on Object
· Send_keys analog key input on the object
· Clear clears the contents of the object, if possible
. Submit Submission Form
Actionchains class
Context_click () Right-click
Double_click () Double-click
Drag_and_drop () drag
Webelement Other common methods:
· Text gets the literal of the element
· Submit Form
· Get_attribute Getting property values
Example: Login Baidu fromSeleniumImportWebdriverImportT
Hantomjs") Driver=Webdriver. PHANTOMJS ()returnDriverElse: Print("Not found this browser,you can use ' Firefox ', ' Chrome ', ' ie ' or ' phantomjs '") exceptException as msg:Print("The exception occurred when starting the browser:%s"%str (msg))Multithreading launches different browsers1. Code reference:#Coding:utf-8 fromSeleniumImportWebdriverImport Time fromTomorrowImportThreadsdefStartbrowser (name):"""Open Browser functions, "Firefox", "Chrome", "ie", "PHANTOMJS"""" Try:
).context_click(right_click).perform() print(‘成功右击‘)except Exception as e: print(‘fail‘)#输出内容:成功双击Attention:
Actionchains (Driver): Call the Actionchains () class and pass the browser driver browser as a parameter
Context_click (Right_click): Analog mouse Double-click, need to pass in the specified element positioning as a parameter
Perform (): performs all the operations stored in Actionchains () as a series of operations prior to execution
1. Right-click
Co
1. Introduce the JAVA+SELENIUM+POM Automatic test framework, the first to realize the separation of code and account URL and other information. The 2nd supports cross-browser implementation by reading the configuration file.1) Add information such as account URL to the properties file and read2) write the browser class by fetching the configuration file to achieve browser switching3) Test Browser classProject structure:1. Create a new folder place the
secondiframe = Driver.find_elements_by_tag_name (' iframe ') [1]# Switch to the IFRAMEDriver.switch_to_frame (IFRAME)# Click to open the File upload buttonDriver.find_element_by_name (' file '). Click ()Time.sleep (3)# Execute AutoIt Upload filePrint IOs.system ("C:\Users\Gloria\Desktop\cmdjpg.exe%s"% i) # your own local. exe pathTime.sleep (3)Driver.switch_to_default_content () # cut back to the main page# # Method Two: Cycle Click Upload Image# for I in range (4):# # 1 O'Clock Open editor pic
Finally, I stepped into the path of learning automation. Originally is to exclude the code, but did not think really seriously to learn the time, found that he is interesting, finished homework feel good to have a sense of accomplishment. Learning process, also encountered a lot of problems, try to find a solution to the problem, can not find a solution, there are colleagues to ask. This kind of learning opportunity, very rare AH.Have now learned the
input box, the data is passed into Send_keys (Hzy). This is called by loop until all the contents of the file are read.Second, login parameterizationNow according to the above ideas, the Automation script user, the name of the password parameterized, through the Python document we found that Python read the file: The entire file read, read-line, fixed byte read.Did not find a good way to read two data at a time.Create two files, each of which holds t
ObjectiveSome small partners learned selenium alert, no matter what pop-up box to use alert, this is not working, see the Popup box, first to determine whether it is alert, is to use, not the words certainly can not be used.
Some pop-up boxes are div layers, which are like normal positioning methods
Some pop-up boxes are nested IFRAME layers, which can be switched by IFRAME
Some pop-up boxes compare pits, which are embedded in a windo
buttonDRIVER.FIND_ELEMENT_BY_ID ("download-btn"). Click () Four, chrome configuration#Coding:utf-8 fromSeleniumImportWebdriverprofile=Webdriver. Chromeoptions () prefs= {'profile.default_content_settings.popups': 0,#set to 0 to suppress pop-up windows 'download.default_directory':'d:\\'}#Specify the download pathProfile.add_experimental_option ('prefs', Prefs)#Executable_path This is the path to chromedriver. If the environment variable is set, this parameter can be omittedChromedriver_
First install the environment you can refer to this article https://www.zhihu.com/question/30496889I use Chrome to browse, download Webdriver's address is http://chromedriver.storage.googleapis.com/index.html,Click to download the historical version of Chrome: https://www.chromedownloads.net/Note that the downloaded version must correspond to its own version of Chrome, or the error will be as follows: version support for Chromedriver can be viewed from http://npm.taobao.org/mirrors/chromedriver/
) to locate the child element, which is the XPath The wording is very different, in fact, very good understanding, direct translation came to the first few childrenSix, CSS: Logical Operations1.css can also implement a logical operation, matching two properties, which is not the same as XPath, no need to write the and keywordSeven, CSS: Fuzzy Matching1.css Fuzzy matching contains (' xxx '), although the Internet with a variety of data display can be used, but the small part of the test in perso
This is a method that can be called directly in mainprivate static void ie () {Webdriver Driver;IE started successfully, files is to start IE driverSystem.setproperty ("Webdriver.ie.driver", "Files/iedriverserver.exe");Code off IE some configurationDesiredcapabilities DC = Desiredcapabilities.internetexplorer ();Dc.setcapability (Internetexplorerdriver.introduce_flakiness_by_ignoring_security_domains, true);Dc.setcapability ("Ignoreprotectedmodesettings", true);Load shutdown configuration into I
As shown, a progress bar control may appear on some Web pages, and the control's structure code is first clarified when it is processed, such as:The control here consists of three parts: a progress bar, a slider, and an input box. The input box has been introduced before, no longer tellsThe progress bar can get the current value through the Title propertySpecific operation can be achieved through the actionchains in the Move_by_offset to achieve the movement of the slider, the specific code is a
1.xptah can be positioned by the attributes of the element's ID, name, classDriver.find_element_by_xpath ("//input[@id = ' kw1 ']")Driver.find_element_by_xpath ("//*[@name = ' wd ']")Driver. Find_element_by_xpath ("//*[@class = ' s_ipt ']") 2. If an element ID, name, and class attribute are not available, you can also navigate to theDriver.find_element_by_xpath ("//*[@autocomplete = ' off ']")Driver.find_element_by_xpath("//input[@type = ' text ']")3. Logical operation4.xpath IndexDriver.find_el
1. Wait methodThe sleep method of the time module is inefficientImplicitly_wait () Set Webdriver wait time, wait, wait, all elements are loaded.Webdriverwait wait for the condition to be met or timeout after exiting the display retry waitFrom Selenium.webdriver.support.ui import webdriverwaitExample 1:Browser.implicitly_wait (5)browser.find_element_by_id (' KW1 ')5 Seconds to view no KW1 elements and then an error.Example 2:From Selenium.webdriver.support.ui import webdriverwaitdef get_ele_times
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") #文本框输入find_element_by_id ("button "). Click () #点击按钮操作(2) Common oper
= ' login ']"). Click () #使用Xpthon定位登录按钮 #d=driver.switch_to_ Alert () .text #获取点击登录后, Pop-up dialog Contents #driver.switch_to_alert (). Accept () #获取对话框焦点, accepting dialog box Contents # ifuser== ': print (' Enter an empty user name, enter a blank password, Prompt as follows: ') elifpwd== ': print (' Enter the user name%s, enter the password is empty%s, prompt as follows: '% (user,pwd)) #打印输入的用户名和密码 #else: print (' Enter the user name%s, enter the password for%s, prompt as follows: '% (user,
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.