Python 3.5 + selenium 3.4 automated test 7_selenium's Webdriver_API collation (below)

Keywords: Selenium Lambda IE Firefox

7. Setting the waiting time

#Import the time package 
import time

#Add Intelligent Waiting 
driver.implicitly_wait(30) 

#Adding Fixed Dormancy Time 
time.sleep(5)



#Import the WebDriverWait package 
from selenium.webdriver.support.ui import WebDriverWait 

#Detailed formats are as follows:
WebDriverWait(driver,timeout,poll_frequency=0.5,ignored_exceptions=None)

driver - WebDriver Driver(Ie,Firefox,Chrome Or remote)

timeout - Maximum timeout, default in seconds

poll_frequency- Hibernation interval (step length) time, default to be ____________ 0.5 second

ignored_exceptions - Exception information after timeout, thrown by default NoSuchElementException Abnormal.


element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("someId")) is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)). until_not(lambda x: x.find_element_by_id("someId").is_displayed()) 

8. Locate the elements in the frame

driver.switch_to.frame("mainscreen")#Cut into the nesting of id="mainscreen"
driver.switch_to.default_content()#This sentence is to exit the original nesting and return to the original main document.
driver.switch_to.parent_frame()Return to the previous level frame

9. Browser Multi-Window

#Get the current window 
nowhandle=driver.current_window_handle
#Get all windows
allhandles=driver.window_handles

for handle in allhandles:
    if handle != nowhandle: 
        driver.switch_to_window(handle) #To the last window

        driver.close()#Close the last window

10.alert/confirm/prompt processing

driver.switch_to_alert().text #Get warning information on the web page
driver.switch_to_alert().accept #Receive warning information 
driver.switch_to_alert().dismiss #Cancel the dialog box (if any) 
driver.switch_to_alert().send_keys("xx") #Input value (if any) 

11. Dropdown Box Processing

from selenium.webdriver.support.ui import Select
Select(driver.find_element_by_id('language')).select_by_value(Value)

12. File upload

driver.find_element_by_name("file").send_keys('D:\\selenium_use_case\upload _file.txt') #send_keys() sends a local file path. So as to achieve the purpose of uploading documents.

13.cookie message processing

driver.get_cookies() # Get all cookie information
driver.get_cookie(name)# Returns cookie information for a specific name
driver.add_cookie({'name':'key-aaaaaaa', 'value':'value-bbbb'})#Add session information to cookie's name and value. 
driver.delete_cookie("CookieName") 
driver.delete_cookie("CookieName") #Delete cookie information for a specific (partial) cookie
driver.delete_all_cookies()# Delete all cookie s 

———————————————— The dividing line

With the long-term update of the actual use case code, this paper introduces the knowledge points in selenium usage. I hope you will pay attention to them.

Focus on Wechat Public Number:

Push selenium knowledge points regularly. Later, I will build my own test system in Aliyun to provide complete test execution cases, so that interested people can experience it. Please continue to pay attention to it.

Posted by killfall on Thu, 14 Feb 2019 16:12:19 -0800