当前位置:网站首页>Selenium library 4.5.0 keyword explanation (III)
Selenium library 4.5.0 keyword explanation (III)
2022-07-03 23:36:00 【Mark community】
SeleniumLibrary4.5.0 Keyword details ( 3、 ... and )
Library version :4.5.0
Library scope : overall situation
Named parameters : Supported
brief introduction
SeleniumLibrary yes Robot Framework Of Web Test library .
This document explains how to use SeleniumLibrary Keywords provided . About installation , Support and other information , Please see the python3.9.0 + robotframework + selenium3 Instance experience .
of robotframework More information about the framework , Please see the https://blog.csdn.net/mask5726/category_10537277.html.
SeleniumLibrary Use... Internally Selenium WebDriver Module to control Web browser . About general Selenium For more information , Please see the Selenium.
The content list
1、 Element localization
2、 Browsers and windows
3、 Overtime , Wait and delay
4、 Operation fault function
5、 Boolean parameters
6、webDriver event
7、 Thread support
8、 plug-in unit
9、 introduce
11、 keyword
Overtime 、 Wait and delay
This section discusses how to wait for elements to appear on Web pages and different ways to slow down execution in other ways . It also explains how to set various timeouts , The time format that can be used when waiting and delaying .
Overtime (timeout)
SeleniumLibrary Contains various keywords , These keywords have optional timeout parameters , This parameter specifies how long these keywords should wait for certain events or operations . These keywords include, for example Wait … Keywords and alarm related keywords . in addition , Asynchronous execution Javascript. Although it has no timeout parameter , But it uses timeouts to define asynchrony JavaScript How long it can run .
The default timeout used by these keywords can be achieved by using Set Selenium Timeout Keyword to set globally , You can also import the library with timeout Parameters are set together . About the supported timeout syntax , See time format below .
An implicit wait (Implicit wait)
Implicitly waiting for the specified search element Selenium How long is the maximum waiting time . When importing a library , have access to Set Selenium Implicit Wait Keyword to set , You can also use implicit_wait Parameter to set . More information about this feature , Please see the Selenium file .
About supported syntax , See time format below .
selenium Execution speed
By using Set Selenium speed Keyword global reduction Selenium Execution speed of . This function is intended for demonstration or debugging purposes . It's not a good idea to use it to ensure that elements appear on the page . Use the timeout and wait mentioned above instead .
About supported syntax , See time format below .
Time format
All timeout and waiting times can be in seconds ( for example 0.5 or 42) Or use Robot Framework Time grammar ( for example 1.5 seconds or 1 min 30 s) To give . More information about time grammar , Please see the 《 Robot Framework User guide 》.
Fault operation function
SeleniumLibrary It has convenient functions , If any of its own keywords fail , It can automatically execute keywords . By default , It USES Capture Page Screenshot keyword , But when importing the Library , By using Register Keyword Run keywords on failure or with run_on_failure Parameters are changed together . You can use any keyword in any imported library or resource file .
You can use special values NOTHING Or any value that is considered wrong ( See Boolean parameters )( for example NONE) To disable the run failure function .
Boolean parameters
Some keywords are accepted as Boolean values true or false Processing parameters . If such a parameter is given as a string , If the parameter is empty or case insensitive , be equal to false,no,off,0 or none, Consider it false. Regardless of the value of other strings , They all think they are right , And use with Python The same rules in test other parameter types .
Ture Example :
Set Screenshot Directory KaTeX parse error: Expected 'EOF', got '#' at position 30: …ersist=True #̲ The string is usually true. Se…{RESULTS} persist=yes # Same as above .
Set Screenshot Directory R E S U L T S p e r s i s t = {RESULTS} persist= RESULTS persist={TRUE} # Python True by true.
Set Screenshot Directory R E S U L T S p e r s i s t = {RESULTS} persist= RESULTS persist={42} # Not 0 The number of true.
False Example :
Set Screenshot Directory KaTeX parse error: Expected 'EOF', got '#' at position 31: …rsist=False #̲ character string false by false.…{RESULTS} persist=no # in addition , character string no by false.
Set Screenshot Directory KaTeX parse error: Expected 'EOF', got '#' at position 30: …ersist=NONE #̲ character string NONE by false.…{RESULTS} persist=KaTeX parse error: Expected 'EOF', got '#' at position 12: {EMPTY} #̲ The empty string is false. Se…{RESULTS} persist=KaTeX parse error: Expected 'EOF', got '#' at position 12: {FALSE} #̲ Python False by f…{RESULTS} persist=${NONE} # Python None by false.
Please note that , stay SeleniumLibrary 3.0 Before , All non empty strings ( Include false,no and none) Are considered true. from SeleniumLibrary 4.0 Start , character string 0 and off Be regarded as false.
WebDriver event
SeleniumLibrary Provide right EventFiringWebDriver Support for . For more details , see also Selenium and SeleniumLibrary EventFiringWebDriver Supporting documentation .
SeleniumLibrary 4.0 Added in EventFiringWebDriver.
EventFiringWebDriver yes Selenium Provided API Listener type of . EventFiringWebDriver Allow listening Selenium API call , And allow users to Selenium API Trigger events before and after methods . see also Selenium EventFiringWebDriver file , What support Selenium API Methods and EventFiringWebDriver How it works .
Selenium EventFiringWebDriver file
class :
class selenium.webdriver.support.event_firing_webdriver.EventFiringWebDriver(driver, event_listener)[source]
A wrapper around an arbitrary WebDriver instance which supports firing events
Creates a new instance of the EventFiringWebDriver
Args:
driver : A WebDriver instance
event_listener : Instance of a class that subclasses AbstractEventListener and implements it fully or partially
Example :
from selenium.webdriver import Firefox
from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener
class MyListener(AbstractEventListener):
def before_navigate_to(self, url, driver):
print(“Before navigate to %s” % url)
def after_navigate_to(self, url, driver):
print(“After navigate to %s” % url)
driver = Firefox()
ef_driver = EventFiringWebDriver(driver, MyListener())
ef_driver.get(“http://www.google.co.in/”)
Method :
back()[source]
close()[source]
execute_async_script(script, *args)[source]
execute_script(script, *args)[source]
find_element(by=‘id’, value=None)[source]
find_element_by_class_name(name)[source]
find_element_by_css_selector(css_selector)[source]
find_element_by_id(id_)[source]
find_element_by_link_text(link_text)[source]
find_element_by_name(name)[source]
find_element_by_partial_link_text(link_text)[source]
find_element_by_tag_name(name)[source]
find_element_by_xpath(xpath)[source]
find_elements(by=‘id’, value=None)[source]
find_elements_by_class_name(name)[source]
find_elements_by_css_selector(css_selector)[source]
find_elements_by_id(id_)[source]
find_elements_by_link_text(text)[source]¶
find_elements_by_name(name)[source]
find_elements_by_partial_link_text(link_text)[source]
find_elements_by_tag_name(name)[source]
find_elements_by_xpath(xpath)[source]
forward()[source]
get(url)[source]
quit()[source]
wrapped_driver
Returns the WebDriver instance wrapped by this EventsFiringWebDriver
class :
class selenium.webdriver.support.event_firing_webdriver.EventFiringWebElement(webelement, ef_driver)[source]
” A wrapper around WebElement instance which supports firing events
Creates a new instance of the EventFiringWebElement
Method :
clear()[source]
click()[source]
find_element(by=‘id’, value=None)[source]
find_element_by_class_name(name)[source]
find_element_by_css_selector(css_selector)[source]
find_element_by_id(id_)[source]
find_element_by_link_text(link_text)[source]
find_element_by_name(name)[source]
find_element_by_partial_link_text(link_text)[source]
find_element_by_tag_name(name)[source]
find_element_by_xpath(xpath)[source]
find_elements(by=‘id’, value=None)[source]
find_elements_by_class_name(name)[source]
find_elements_by_css_selector(css_selector)[source]
find_elements_by_id(id_)[source]
find_elements_by_link_text(link_text)[source]
find_elements_by_name(name)[source]
find_elements_by_partial_link_text(link_text)[source]
find_elements_by_tag_name(name)[source]
find_elements_by_xpath(xpath)[source]
send_keys(*value)[source]
wrapped_element
Returns the WebElement wrapped by this EventFiringWebElement instance
adopt Selenium EventFiringWebDriver We can see the document ,selenium Of webdriver The monitor can be in webdriver Perform some operations before and after the instance of , The method of encapsulation can be through id、name、css、 link 、xpath、tag To identify elements .
Thread support
SeleniumLibrary Not thread safe . This is mainly because of the bottom Selenium Tools in a browser / The driver instance is not thread safe . because Selenium Limitations in the field ,SeleniumLibrary Keywords provided or API Not thread safe .
plug-in unit
SeleniumLibrary Provide plug-ins , As a way to modify and add library keywords and modify some internal functions , Without creating new libraries or modifying the source code . For more details , See plug-ins API file .
plug-in unit API be based on SeleniumLibrary 4.0 A new version of the
introduce
We are introducing seleniumlibrary List of parameters that can be used in Library :
timeout=5.0
implicit_wait=0.0
run_on_failure=Capture Page Screenshot
screenshot_root_directory=None
plugins=None
event_firing_webdriver=None
SeleniumLibrary The following parameter settings can be used when importing :
timeout: And Wait … The default value of timeout used with keywords .
implicit_wait: The default value of implicit waiting used when locating elements .
run_on_failure: The default value of implicit waiting used when locating elements (Capture Page Screenshot Take a screenshot when it fails ).
screenshot_root_directory: Create possible screenshots or EMBED The path to the folder . of EMBED For more details , See set screenshot directory keywords . If not provided , Then use the directory where the log file is written .
plugins: Allow the use of external Python Class extensions SeleniumLibrary.
event_firing_webdriver: Use EventFiringWebDriver packing selenium class .
边栏推荐
- Interesting 10 CMD commands
- Minimum commission for stock account opening. Stock account opening is free. Is online account opening safe
- Schematic diagram of crystal oscillator clock and PCB Design Guide
- Hcip day 14 notes
- Apple released a supplementary update to MacOS Catalina 10.15.5, which mainly fixes security vulnerabilities
- Make small tip
- Errors taken 1 Position1 argument but 2 were given in Mockingbird
- The interviewer's biggest lie to deceive you, bypassing three years of less struggle
- URLEncoder. Encode and urldecoder Decode processing URL
- 2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
猜你喜欢

How to understand the gain bandwidth product operational amplifier gain

Smart fan system based on stm32f407

Qtoolbutton available signal

Enter MySQL in docker container by command under Linux

Tencent interview: can you pour water?
![[Happy Valentine's day]](/img/d9/9280398eb64907a567df6eea772adb.jpg)
[Happy Valentine's day] "I still like you very much, like sin ² a+cos ² A consistent "(white code in the attached table)

EPF: a fuzzy testing framework for network protocols based on evolution, protocol awareness and coverage guidance
![[MySQL] classification of multi table queries](/img/96/2e51ae8d52ea8184945e0540ce18f5.jpg)
[MySQL] classification of multi table queries

Alibaba cloud container service differentiation SLO hybrid technology practice

Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition
随机推荐
Subset enumeration method
Go error collection | talk about the difference between the value type and pointer type of the method receiver
File copy method
In VS_ In 2019, scanf and other functions are used to prompt the error of unsafe functions
How to make icons easily
D23:multiple of 3 or 5 (multiple of 3 or 5, translation + solution)
Gossip about redis source code 81
Current detection circuit - including op amp current scheme
D29:post Office (post office, translation)
Amway by head has this project management tool to improve productivity in a straight line
Comment obtenir une commission préférentielle pour l'ouverture d'un compte en bourse? Est - ce que l'ouverture d'un compte en ligne est sécurisée?
How to quickly build high availability of service discovery
Gossip about redis source code 78
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Qtoolbutton available signal
After the Lunar New Year and a half
Selenium check box
Esp-idf turns off serial port log output.
C # basic knowledge (3)
Xiangong intelligent obtained hundreds of millions of yuan of b-round financing to accelerate the process of building non-standard solutions with standardized products