当前位置:网站首页>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')
边栏推荐
- How about the VIP domain name? Does the VIP domain name need to be filed after registration?
- What is a Chinese domain name? What are the types of Chinese domain names?
- [JS reverse hundred examples] Dangle login interface parameters reverse
- Install and use juicefs storage on Tencent cloud
- How to apply for a company domain name? What are the requirements for the applicant company?
- Tencent cloud harbor private warehouse deployment practice
- [performance test] 3 How to calculate the number of concurrent users
- How to get the website domain name? Does it cost money to apply for a website domain name?
- How do individuals register domain names? What are the precautions for individual domain name registration?
- Detailed explanation of IPv6 theory and concept
猜你喜欢
随机推荐
How to build a website after registering a domain name? Do you need maintenance later?
How to buy a network domain name? Is the domain expensive
The website cannot be opened after windows installs the dongle
How do individuals register domain names? What are the precautions for individual domain name registration?
Havip+keepalived high availability building
Spirit information development log (4)
How about the XYZ domain name? What are the advantages over other domain names?
What should I pay attention to in server hosting and migration?
Is the prospect of cloud computing in the security industry worth being optimistic about?
[dry goods] flexible force control grinding tools promote the "smart" transformation of automatic grinding production!
How to solve the problem that easynvr calls the video download interface of the specified time period to display "being synthesized" and does not generate video?
How to do domain name resolution? What does domain name resolution mean?
Summary of basic notes of C language (I)
How do users purchase domain names? What should I pay attention to when buying a domain name?
Hacking with Golang
Sub process call - process arrangement in complex O & M scenarios
How to resolve the primary domain name and how to operate it
How to make a secondary domain name? What are the advantages of secondary domain names?
His secret script of hard technology investment
How to register domain name and web address? What is the domain name and URL?