selenium automated testing interview questions

 

Reprinted from: https://www.cnblogs.com/peipei-Study/p/11977237.html

Thank big brother!

 

(1) the principle of selenium?

       ① script starts driver

       ② driver to drive the browser as a remote server

       ③ execution script transmission request

       ④ server resolution request the corresponding operation, and returns to the client (script)

(2) cause of the abnormality selenium automation page elements exist can not find?

        ① element positioning error

        ② page load time is too slow, need to find the elements of the program have been completed, yet a single page to load, then you can load the page wait time

        ③ possible frame or iframe element contained in the inside, to be switched.

(3) how to position elements dynamically changing attributes?

        Dynamic changes of properties means that the property value element is not fixed only by the relative position location.

        A first method: a traverse findelements

        The second method: the parent xpath through the shaft / following-sibling / precent-sibling

(4) how to locate elements on the page dynamically loaded?

        Dynamic event trigger, then findelement; if it is a dynamic menu, you need to find a level.

(5) selenium call js (execute_script), which scene?

        ① perform input for input

        ② for rich text box

        ③ scroll to the specified position of the operation

How (6) selenium processing web popups? js pop?

       Need to use driver.switch_to.alert ()

(7) selenium can handle window pop it?

       selenium itself is not processing windows pop, but AutoIT can make use of gadgets to complete the operation on the windows popups. Such as uploading and downloading attachments, etc.

(8) How to highlight elements in the positioning element (debug purposes)?

        The use of javascript border or background color of the element can be changed to yellow or other colors

(9) selenium supports automated testing desktop applications?

        not support. The attribute page element selenium is in the range of elements to

(10) selenium Is there a library to read excel file?

        There is no need to use third-party tools. Plug-ins such as Apache PIO

(11) whether selenium can send mouse wheel to operate the page?

        Can not.

(12) How to call in the application webdriver?

       driver.get('url')  或者 driver.navigate().to('url')

Common abnormality (13) selenium in?

       NoSuchElementException can not find a page element anomaly

       ElementNoInteractac tableException

(14) selenium Why not recommended xpath positioning?

       When using selenium traversing page using xpath targeting poor performance. In addition xpath positioned by the positioning of an absolute path, sometimes inaccurate;

       Css but with the selector positioned relatively simple, faster, normally used for performance critical scene.

(15) How to determine whether there is an element on a page?

       Method 1: The try ... except the code blocks plus

       Method 2: A method and elements defined in the element group number of the root element of its len () <1 exists returns True, False if not present

       Method 3: Analyzing binding WebDriverWait and excepted_conditions conditions (strongly recommended)

                Display waiting time Analyzing intervals of 1 second, 30 seconds time-out, there is a return True, False if not present

(16) How to locate dynamic elements?

       Dynamic elements there are two cases:

              Is a dynamic attribute, the positioning, if id is dynamic, not use id positioning, the positioning elements other methods

              This is another element in the top of the page for a while, for a while at the bottom, erratic, positioning method is the same, according to the positioning element attributes (tag name attribute of the element will not change, moving only class attributes and style attributes)

(17) How the child element positioned parent element?

       By locating the parent child element, you can be found by a secondary positioning.

             The first: by positioning the child element of the parent element, parent provides a method of Selenium, but only to locate the parent element, but can not obtain the element properties can not be operated.

             The second: located directly by the xpath syntax. The points represent two .//*[@name="hello"]/ .. parent element.

(18) how to intercept a picture element, do not intercept all the pictures?

       The preferred interception of the current page and save custom

       Then acquires coordinates and size of the element to be taken ele.location ele.size element according to image properties

       And then were left = ele.location [ 'x']

                     top = ele.location [ 'and']

                     right = ele.location['x'] + ele.size['width']

                     bottom = ele.location['y'] + ele.size['height']

       Get a picture of the element size coordinates

       Finally, beginning opened again saved by methods crop image class (corresponding to a rectangular area copy of the element), and then do the save operation on it.

(19) an element clearly positioned, click on the invalid (no error), how to solve?

       Click js use, will lapse at the click element selenium sometimes

       # Js Click

       js = 'document.getElementById('baidu').click()'

       driver.execute_script(js)

(20) How to improve the stability of the script?

       First, as long as the page has not changed, indicating positioning method is no problem.

       Optimization direction: ① write their own relative path, mostly to find a node id, xpath less copy right, the kind of instability.

                         ② The second factor is the impact of waiting, sleep wait as little as possible (affect the execution time)

                         ③ positioning method reseal element, and binding WebDriverWait excepted_conditions element determination method, a positioning element method own package

(21) improve execution speed mode selenium script?

       Reduce unnecessary operations.

       Too much and does not affect page load test, you can set the timeout interrupt the page loads.

       When setting the waiting time, you can sleep () a fixed time after detecting an interruption element may also increase the speed of waiting.

       Configuring testNG multi-threaded, in the preparation of test cases, we must achieve loose coupling, in the case of server allows multiple threads to run as far as possible to set and improve execution speed.

When (22) selenium automation, in peacetime encountered those problems? How to solve?

       Such as dynamic id, there is the iframe situation, and other factors did not increase waiting

(23) selenium hidden element positioning, what should you do?

       Hidden element to be positioned correctly, but can not be operated (operating element and the positioning element is different, the operating element means a click, clear, send_keys these and the like). We can use js to manipulate the hidden elements. Js different and selenium, only some elements of the page (in the dom inside) can be normal operation.

(24) upload pictures of ways?

       send_keys and tools to achieve AutoIT

(25) shots should be how to operate?

       driver.get_screenshot_as_file('C:\test.jpg')

Guess you like

Origin www.cnblogs.com/wuduoduo41/p/12355338.html