当前位置:网站首页>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 .
边栏推荐
- 2022.02.14
- Introduction to the gtid mode of MySQL master-slave replication
- A treasure open source software, cross platform terminal artifact tabby
- Research Report on the scale prediction of China's municipal engineering industry and the prospect of the 14th five year plan 2022-2028
- EPF: a fuzzy testing framework for network protocols based on evolution, protocol awareness and coverage guidance
- I wrote a chat software with timeout connect function
- SQL data update
- Shiftvit uses the precision of swing transformer to outperform the speed of RESNET, and discusses that the success of Vit does not lie in attention!
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- finalize finalization finally final
猜你喜欢
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Yyds dry goods inventory [practical] simply encapsulate JS cycle with FP idea~
leetcode-43. String multiplication
How to prevent malicious crawling of information by one-to-one live broadcast source server
2022 free examination questions for hoisting machinery command and hoisting machinery command theory examination
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Pyqt5 sensitive word detection tool production, operator's Gospel
Exclusive download! Alibaba cloud native brings 10 + technical experts to bring "new possibilities of cloud native and cloud future"
Idea set class header comments
[Happy Valentine's day] "I still like you very much, like sin ² a+cos ² A consistent "(white code in the attached table)
随机推荐
Gorilla/mux framework (RK boot): add tracing Middleware
China standard gas market prospect investment and development feasibility study report 2022-2028
2.14 summary
2022.02.14
Sword finger offer day 4 (Sword finger offer 03. duplicate numbers in the array, sword finger offer 53 - I. find the number I in the sorted array, and the missing numbers in sword finger offer 53 - ii
D26: the nearest number (translation + solution)
Les sociétés de valeurs mobilières dont la Commission d'ouverture d'un compte d'actions est la plus faible ont ce que tout le monde recommande.
ADB command to get XML
Powerful blog summary
[issue 16] golang's one-year experience in developing Purdue Technology
2022 t elevator repair registration examination and the latest analysis of T elevator repair
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Hcip 13th day notes
D25:sequence search (sequence search, translation + problem solving)
[untitled]
Live app source code, jump to links outside the station or jump to pages inside the platform
In VS_ In 2019, scanf and other functions are used to prompt the error of unsafe functions
Gossip about redis source code 82
在恒泰证券开户怎么样?安全吗?
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination