This section focuses on:
L Keyboard Key Usage
L Keyboard key combination usage
L Send_keys () input Chinese run error problem
Keyboard Key Usage:
#coding =utf-8 from
Selenium import webdriver The
import keys from Selenium.webdriver.common.keys #需要引入keys包
Import os,time
driver = webdriver. Firefox ()
driver.get ("Http://passport.kuaibo.com/login/?referre
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
First, the browser to maximizeSecond, set the browser resolution sizeThird, print the page titleFour, print the URLV. Control browser forward or backward#!/usr/bin/env python#-*-Coding:utf-8-*-From selenium import WebdriverImport timeBrowser = Webdriver. Firefox ()#浏览器最大化Browser.maximize_window ()#设置浏览器分辨率大小Browser.set_window_size (800,600)#访问百度首页Index_url = "Htt
Unlike the "HTML element Positioning " Article, this article mainly records the various control operations of selenium. 1. Modify page element properties.Requirements Scenario: Take the Solution: It seems that Webdriver does not change the original information of the page, but it provides an interface that can manipulate JavaScript scripts, which can modify the attributes of the elements smoothly.Specific i
As a just contact with Python, the first time programming, the first attempt to do an automated slag, to witness their progress, perhaps every step for others, but for their own, is countless times to take a step forward, very laborious, but also very gratified. Nonsense not much to say, into the subject.I use Python+selenium
= driver.find_element_by_name ("cheese")OrFrom selenium.webdriver.common.by Import byCheese = driver.find_element (by.name, "cheese")by Link TextAn example of how to find an element such as the following:Cheese = Driver.find_element_by_link_text ("cheese")OrFrom selenium.webdriver.common.by Import byCheese = driver.find_element (by.link_text, "cheese")by Partial Link TextAn example of how to find an element such as the following:Cheese = Driver.find_element_by_partial_link_text ("cheese")OrFrom
before.Webdriverwait (DR, 10)Scans 1 page changes every 500 milliseconds in 10 seconds, ending when the specified element appears. Dr does not explain that the handle of the front operation Webdriver.firefox ()Is_displayed ()Whether the element is visible to the userClass Actionchains (Driver)Driver: Performing a user action instance webdriverGenerates the user's behavior. All actions are stored in the actionchains object. behavior that is stored through the perform (). Move_to_element (menu)Mo
This section focuses on:
Calling the JS method
Execute_script (script, *args)
Performs JavaScript synchronously in the current window/frame
Script: The execution of JavaScript.
* Parameters: Applicable to any JavaScript script.
Use:
Driver.execute_script (' Document.title ')
Make the fast-seeding login user name input box marked red display:
#coding =utf-8 from
Selenium import webdriver
import tim
This section focuses on:
Uploading files
File upload operation is also one of the most common functions, upload function is not used to new methods or functions, the key is thinking.
The upload process typically opens a local window and selects the local file to add from the window. So, generally will card in how to operate the local window to add upload files.
In fact, in selenium webdriver not so compl
From selenium import WebdriverFrom Pathlib import PathFrom time import sleepDriver = Webdriver. Chrome ()Driver.get ("http://www.baidu.com")driver.find_element_by_id (' kw '). Send_keys (' Selenium ')driver.find_element_by_id (' su '). Click ()Sleep (5)# Truncate the current window and specify where to save the pictureI=1Scrpath= "C:\\users\\whu024\\desktop\\amyp
Configure browser settings in python + selenium webdriver. firefox () mode,
Webdriver. firefox () crawler requirements: (the input token can be obtained. Zip/pdf files, and then click to download)
-- The firefox browser has a Bug. A pop-up window is displayed after you click Download. You need to click OK. How can this
)For example, frame a nested this frame B, you now need to position the text box in frame BSwitch_to_frame (id == b) find_element_by_id ("textboxid")After you have positioned the popup frame, you need to jump out of the frame to locate the elements on the original page.Driver.switch_to_frame ("layui-layer-iframe1") #定位框架 ... driver.switch_to_ Default_content () jump out of frame Driver.find_element_by_xpath ("html/body")Seleniu
Keys.enterDelete key Keys.back_spaceSpace bar Keys.spaceTAB key Keys.tabFallback key Keys.escapeRefresh Key Keys.f5
Here we choose a common key, to write an example, use the ENTER key instead of the mouse click ()#-*-coding:utf-8-*- fromSelenium.webdriver.common.keysImportKeys fromSeleniumImportWebdriverImportTimedriver=Webdriver. Chrome () Driver.maximize_window () Driver.get ("http://cn.bing.com/") driver.find_element_by_id ('sb_form_q'). Send
The previous mentioned a lot of knowledge are positioning elements, positioning is only the first step, after the positioning of the original element to operate.
Mouse click or keyboard input, depending on our positioning is the button also input box.
In general, there are several ways to compare commonly used objects in Webdriver
· Click Object
· Send_keys to simulate key input on an object
· Clear clears the contents of the object, if possible
= self.driver.find_element_by_id ('LoginName') - +REGISTER_BTN = self.driver.find_element_by_id ('submitbtn') A at #Check that the maximum allowable input characters and minimum input characters in a field are the same as expected - -Self.assertequal ('2', User_login_name.get_attribute ('Data-val-length-min')) - -Self.assertequal (' -', User_login_name.get_attribute ('Data-val-length-max')) - in #check that each field and button are visible to the user and available - toSelf.asser
This section knowledge points:
Positioning of a multi-tier frame or window:
Switch_to_frame ()
Switch_to_window ()
Smart wait:
Implicitly_wait ()
For a modern web application, there are often frames or Windows (window) applications, which poses a challenge to our positioning.
Sometimes we locate an element, the locator is not a problem, but it is not fixed, this time we have to check whether this element is in a frame, Seelnium Webdriver provide
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.