当前位置:网站首页>25 classic selenium automated interview questions, collect them quickly
25 classic selenium automated interview questions, collect them quickly
2022-06-24 05:55:00 【Programmers who don't drink Chinese wolfberry】
(1)selenium How it works ?
① The script to start driver
② driver To drive the browser as a remote server
③ Execute the script to send the request
④ The server parses the request and takes corresponding actions , And return it to the client ( Script )
(2)selenium The automation page element could not find the reason for the exception ?
① Element positioning error
② Page loading time is too slow , The element program to find has been completed , Single page not loaded yet , Page waiting time can be loaded at this time
③ It is possible that the element is contained in iframe perhaps frame Inside , Need to switch .
(3) How to locate elements with dynamic attributes ?
Property dynamic change refers to the element There is no fixed attribute value , Can only be located by relative position .
The first method : use findelements Traverse
The second method : adopt xpath The shaft parent / following-sibling / precent-sibling
(4) How to locate dynamically loaded elements on a page ?
Trigger dynamic events , then findelement; If it's a dynamic menu , Need level by level find.
(5)selenium call js(execute_script), What are the scenes ?
① Yes input Perform input
② Operations on rich text boxes
③ Scroll to the specified position to operate
(6)selenium How to deal with it web Popup ?js Popup ?
Need to use driver.switch_to.alert()
(7)selenium Can handle window Pop up ?
selenium It cannot be handled by itself windows The popup window , But with the help of AutoIT Gadgets to complete the right windows Pop up window operation . such as Upload and download attachments, etc
(8) How to highlight an element after positioning it ( For the purpose of debugging )?
Use javascript Elemental border Or change the background color to yellow or other colors
(9)selenium Support for automated testing of desktop applications ?
I won't support it .selenium The scope element is determined according to the attributes of the web page element
(10)selenium Is there a read excel Document library ?
No, , Third party tools are needed . for example Apache PIO plug-in unit
(11)selenium Can I send mouse wheel actions to the page ?
You can't .
(12) How to be in webdriver Calling application ?
driver.get('url') perhaps driver.navigate().to('url')
(13)selenium Common exceptions in ?
NoSuchElementException Page element not found exception
ElementNoInteractac tableException
(14)selenium Why not recommend xpath location ?
selenium Use xpath When positioning, it uses the way of traversing the page , Poor performance index . in addition xpath Positioning has the ability to locate through an absolute path , Sometimes inaccurate ;
While using css Selector positioning is relatively simple , Run faster , It is usually used in scenarios with strict performance requirements .
(15) How to determine whether an element on a page exists ?
Law 1: use try...except Add... To the code block
Law 2: use elements Define group element methods Then root the number of elements len()<1 There is returned True, Returns if it does not exist False
Law 3: combination WebDriverWait and excepted_conditions conditional ( Strongly recommend )
According to wait , Every interval 1 Judge once in a second ,30 Second timeout , There is returned True, Returns if it does not exist False
(16) How to locate dynamic elements ?
There are two cases of dynamic elements :
One is attribute dynamics , When positioning , if id Is dynamic , Don't use id location , Use other methods of locating elements
The other is that this element will be at the top of the page , I'll be down there later , Erratic , It's the same with positioning , Positioning by element attributes ( Elemental tag name The properties do not change , What's moving is class Properties and style attribute )
(17) How to locate the parent element through the child element ?
Locate the child element through the parent element , Can be found by secondary positioning .
The first one is : Locate the parent element through the child element ,selenium Provides parent Method , But you can only locate the parent element , But can't get element attributes , You can't operate .
The second kind : adopt xpath The grammatically direct orientation of . Such as .//*[@name="hello"]/.. Two points represent the parent element .
(18) How to intercept the image of an element , Don't take all the pictures ?
It is preferred to intercept the current page and save it in a customized way
Then get the coordinates and size of the element according to the attributes of the element image to be intercepted ele.location ele.size
And then separately left = ele.location['x']
top = ele.location['y']
right = ele.location['x'] + ele.size['width']
bottom = ele.location['y'] + ele.size['height']
Get the coordinate size of the image of the element
Last , Open the newly saved... Again , adopt image Class crop Method ( This is equivalent to copying a rectangular area of the element ), Then you can save it .
(19) An element is clearly positioned , Click invalid ( No mistake ), How to solve ?
Use js Click on ,selenium Sometimes clicking on an element will invalidate
# js Click on
js = 'document.getElementById('baidu').click()'
driver.execute_script(js)
(20) How to improve the stability of scripts ?
First, as long as the page hasn't changed , It shows that the positioning method is OK .
To optimize the direction :① Write your own relative path , multi-purpose id Find... For nodes , Use less right-click copy xpath, That kind of instability .
② The second factor is waiting ,sleep Wait as little as possible ( Affect execution time )
③ Positioning element method repackaging , combination WebDriverWait and excepted_conditions How to judge elements , Encapsulate a set of positioning element methods
(21) Improve selenium How fast the script executes ?
Reduce unnecessary operations .
The page is overloaded and does not affect the test , Timeout can be set to interrupt page loading .
When setting the waiting time , Sure sleep() Fixed time , Interrupting the wait after detecting the occurrence of an element can also increase the speed .
To configure testNG Implement multithreading , When writing test cases , Be sure to achieve loose coupling , Set up multithreading as far as the server allows , Improve execution speed .
(22)selenium When automating , What problems have you encountered at ordinary times ? How to solve ?
Such as dynamic id 、 Yes iframe The situation of 、 No waiting and other factors
(23)selenium Hide element positioning in , How do you do it ?
Hidden elements can be positioned to , It just doesn't work ( Positioning elements and manipulating elements are two different things , Operation elements refer to click 、clear 、send_keys Wait for these methods ). We can use js To manipulate hidden elements .js and selenium Different , Only the elements on the page ( stay dom Inside ) Can operate normally .
(24) There are several ways to upload pictures ?
send_keys and AutoIT Tool implementation .
(25) How should the screenshot work ?
driver.get_screenshot_as_file('C:\test.jpg')
边栏推荐
- Playing "honey in snow and ice city" with single chip microcomputer
- What happened to the JVM locking on Tencent ECS?
- [JS reverse hundred examples] Dangle login interface parameters reverse
- [industry outlook] future development forecast of UHD video application
- Typora software installation
- Netaapp data recovery process
- Some common IPv6 problems!
- Oceanus practice - develop MySQL CDC to es SQL jobs from 0 to 1
- What is a Chinese domain name? What are the types of Chinese domain names?
- MySQL series tutorial (I) getting to know MySQL
猜你喜欢
随机推荐
Several relations to be clarified in the process of digital transformation: stock and increment
How to renew the domain name when it expires
How to build a website with a domain name? Is the website domain name free to use?
How to apply for a domain name? Why should domain names be filed in advance?
Build ZABBIX on Tencent ECS
Spirit information development log (4)
Typora software installation
How to buy a network domain name? Is the domain expensive
How to register a domain name how to select a domain name registrar
New tea: reshuffle, transformation, merger and acquisition
Playing "honey in snow and ice city" with single chip microcomputer
Confirm the importance of requirements at the initial stage of EDI project
Netaapp data recovery process
Less network card filters
How to register domain name and web address? What is the domain name and URL?
Pylin tool usage
Load balancing on Tencent cloud
[dry goods] flexible force control grinding tools promote the "smart" transformation of automatic grinding production!
Progress update | optimization and upgrading of shard nodes
Kubesphere manages multi tke clusters